cinar/indicatorts

build-esm and build-cjs scripts overwrite each other

vesap opened this issue · 4 comments

vesap commented

When building a react project with vite, I got the following error:

Failed to resolve entry for package "indicatorts". The package may have incorrect main/module/exports specified in its package.json.

package.json contains:

"main": "dist/index.js",
"module": "dist/index.es.js",
"types": "dist/index.d.ts",

Looking at the installed files reveals there's no dist/index.es.js:

$ ls -1 node_modules/indicatorts/dist
backtest
chart
company
helper
index.d.ts
index.js
index.js.map
indicator
strategy

Temporarily removing row:

"module": "dist/index.es.js",

from node_modules/indicatorts/package.json seems to fix the build issue.

Looking at the build scripts:

"build": "npm run build-esm; npm run build-cjs; npm run build-types",
"build-esm": "esbuild src/index.ts --bundle --outdir=dist --platform=browser --format=esm --minify --sourcemap",
"build-cjs": "esbuild src/index.ts --bundle --outdir=dist --platform=node --format=cjs --minify --sourcemap",

It seems npm run build-esm creates dist/index.js & dist/index.js-map that npm run build-cjs immediately overwrites. Neither of them is making dist/index.es.js file.

It would be nice if either build-esm was fixed to create dist/index.es.js or the whole "module": "dist/index.es.js" was removed from package.json so vite build would succeed.

Thank you for the awesome library :)

cinar commented

Hi Vesa, Thank you very much for reporting this! Let me take a look and see if I can fix this.

cinar commented

I was able to use dedicated output directories for both ESM and CJS. This should prevent them overwriting each other. Would you mind doing a quick code review, and I can push this?

main.cjs:

helper = require("indicatorts");
console.log(helper.daysAgo(30));

main.mjs:

import { daysAgo } from "indicatorts";
console.log(daysAgo(30));
vesap commented

#406 fixes the issue for me :)

cinar commented

I just published an update with the fix. Just wanted to let you know. Please feel free to re-open this issue, if you run into any problem. Thanks again for using IndicatorTS!

https://github.com/cinar/indicatorts/releases/tag/v1.0.17