New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import { BigNumber } gave an Error #300
Comments
Yes, if you are not using a bundler such as webpack or rollup which uses the import { BigNumber } from "./node_modules/bignumber.js/bignumber.mjs"; Notes: I am not absolutely sure about this, but in earlier versions of Node (<13?), import { BigNumber } from "bignumber.js"; would work, because the "main" field in the package.json here is extensionless, and the old import path resolution algorithm looked for a file with the ".mjs" extension first. See 4.4. Shipping both ESM and CJS and Dual-Mode Packages. That is no longer the case, so now import BigNumber from "bignumber.js"; will actually load the bignumber.js file rather than the bignumber.mjs file, and only the default export is available when importing from CommonJs files, so named exports such as in import { BigNumber } from "bignumber.js"; no longer work. The new import resolver algorithm is here. The solution is to add the "exports" field to the package.json "exports": {
"import": "./bignumber.mjs",
"require": "./bignumber.js"
} but that will prevent importing from subpaths of the package, for example import { BigNumber } from "./node_modules/bignumber.js/bignumber.mjs"; so it likely to cause some users problems initially. I also need to consider typescript, webpack, rollup, angular etc. Related: |
OK, thanks for your help |
Hi,
With NodeJS 14 or 16
import BigNumber from "bignumber.js";
this work fine but
import { BigNumber } from "bignumber.js";
have this error
The text was updated successfully, but these errors were encountered: