-
Notifications
You must be signed in to change notification settings - Fork 172
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
Version 0.9.x starting to give ESM related errors #615
Comments
@antstanley could you please take a look? |
@naorpeled no problem! @kr1p70n1c in "exports": {
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.js"
}
}
},
It adds a root export with two conditions, one for How it decides will be based on whether you have One issue with switching to import { Entity, Table } from 'dynamodb-toolbox/dist/cjs'; then the "exports": {
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.js"
},
},
"./dist/cjs": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.js"
},
},
This adds an explicit export for Some detail on how Conditional Exports work here https://nodejs.org/api/packages.html#conditional-exports Saying that, your existing CommonJS code should just work. You shouldn't need to import from the sub-path. I'm assuming you're writing TS? Can you update the "compilerOptions": {
"module": "CommonJs",
"moduleResolution": "Node",
"esModuleInterop": true,
}
From looking at your error, it looks like its actually a problem with It's a very common error, with a ton of posts how to solve it. The tldr is remove Let me know if you come right. Happy to help. |
Hi there, Thank you so much for the detailed response. I have however tried numerous options and angles already before logging the issue, eg:
to no avail. Only fix I have is to downgrade Here is my
I'm not sure if the I appreciate you helping with this 🙏 |
Not sure if this is the same issue, but I'm having ESM related errors too:
causes Node says
|
@kr1p70n1c @djghokie I think you might have a similar problem, and it could be something missed when setting up dual module support. Basically Node has two ways of telling if a file is CommonJS or ESM. First is by the TypeScript doesn't allow changing file extensions when transpiling. It always outputs One way would be to make all the CommonJS files to have a As TypeScript doesn't transpile to custom extensions, I went the I've made the change by adding the sub-package.json files with correct I was able to reproduce @djghokie's issue, and this resolves it. @kr1p70n1c I haven't been able to reproduce yours, but that's more down to you having a slightly more complex config. Saying that, as Sorry about all of this! |
@antstanley |
When our project's
nyc mocha
executes the error appears:AFAIK this is related to using CJS and ESM in the same environment.
Indeed I notice that with the latest version there are CJS and ESM related changes.
I can not use this import statement:
It results in the error:
The documentation of the project makes no mention of anyting related to:
This begs the question: How to include the CJS artifacts from the
dist
directory if they are not exported.Does anybody else have this issue?
For now I will downgrade to
0.8.x
again to enable our project's test cases to execute.The text was updated successfully, but these errors were encountered: