-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 assertions are not getting stripped out of dynamic import #2036
Comments
This appears to be working correctly: $ echo "import('./bar.json', { assert: { type: 'json' } })" | esbuild --target=node16.14
import("./bar.json", { assert: { type: "json" } });
$ echo "import('./bar.json', { assert: { type: 'json' } })" | esbuild --target=node16.13.2
import("./bar.json"); Are you sure you are using the latest version? What are the steps to reproduce the issue? |
Hmm, maybe there is something in details then. I do Source file, import staticImport from 'test.json' assert { type: 'json' };
console.log('static import transpiles well', staticImport);
export const schemaDocument = (
await import(process.env.SCHEMA_LOCATION!, { assert: { type: 'json' } })
).default; Bundle: $ npx esbuild --bundle ./import-test.ts --target=node16.13.2 --format=esm --external:test.json
// ./import-test.ts
import staticImport from "test.json";
console.log('static import transpiles well', staticImport);
var schemaDocument = (await import(process.env.SCHEMA_LOCATION, { assert: { type: "json" } })).default;
export {
schemaDocument
};
$ npx esbuild --bundle ./import-test.ts --target=node16.14 --format=esm --external:test.json
// ./import-test.ts
import staticImport from "test.json" assert { type: "json" };
console.log('static import transpiles well', staticImport);
var schemaDocument = (await import(process.env.SCHEMA_LOCATION, { assert: { type: "json" } })).default;
export {
schemaDocument
}; |
It seems esbuild cannot handle non-string tokens as the first param of import(a, { assert: { type: 'json' } }) |
Ah, that makes sense. Looks like I missed one of the cases. Will fix. |
7 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Import assertions are mandatory in dynamic import of JSON modules also, starting Node 16.14 - see https://nodejs.org/docs/latest-v16.x/api/esm.html#import-assertions
But they are resulting in error on previous versions of Node, and so, should be stripped when target is below 16.14 (just like with standard import).
I.e.:
The text was updated successfully, but these errors were encountered: