Repository navigation
Provide more information when there is a SyntaxError #56830
Copy link
Copy link
Closed
Labels
strip-typesIssues and PRs related to TypeScript type stripping.Issues and PRs related to TypeScript type stripping.
Description
I'm working on migrating a large JS/TS repo to using Node.js v23 type-stripping. I've already applied some codemods to transform requires & imports, as well as remove TS specific syntax. I'm now running into some syntax errors regarding missing exports which I think were silently being ignored previously. The error does not say what file it is coming from and that is proving difficult to track down. Can amaro print that info? Thank you!
For example:
> node bin/harperdb.js
(node:25707) ExperimentalWarning: Type Stripping is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:25707) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///Users/ethan/dev/harperdb/harperdb/resources/databases.ts is not specified and it doesn't parse as CommonJS.
Reparsing as ES module because module syntax was detected. This incurs a performance overhead.
To eliminate this warning, add "type": "module" to /Users/ethan/dev/harperdb/harperdb/package.json.
SyntaxError: The requested module 'lmdb' does not provide an export named 'Transaction'
at ModuleJobSync.runSync (node:internal/modules/esm/module_job:385:37)
at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:363:47)
at loadESMFromCJS (node:internal/modules/cjs/loader:1569:24)
at Module._compile (node:internal/modules/cjs/loader:1721:5)
at Object.loadTS [as .ts] (node:internal/modules/cjs/loader:1831:10)
at Module.load (node:internal/modules/cjs/loader:1473:32)
at Function._load (node:internal/modules/cjs/loader:1285:12)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:234:24)
at Module.require (node:internal/modules/cjs/loader:1495:12)
2025-01-14T17:11:39.050Z [main/0] [error]: SyntaxError: The requested module 'lmdb' does not provide an export named 'Transaction'
at ModuleJobSync.runSync (node:internal/modules/esm/module_job:385:37)
at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:363:47)
at loadESMFromCJS (node:internal/modules/cjs/loader:1569:24)
at Module._compile (node:internal/modules/cjs/loader:1721:5)
at Object.loadTS [as .ts] (node:internal/modules/cjs/loader:1831:10)
at Module.load (node:internal/modules/cjs/loader:1473:32)
at Function._load (node:internal/modules/cjs/loader:1285:12)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:234:24)
at Module.require (node:internal/modules/cjs/loader:1495:12)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
strip-typesIssues and PRs related to TypeScript type stripping.Issues and PRs related to TypeScript type stripping.
Activity
marco-ippolito commentedon Jan 14, 2025
99% of the time is because you are importing a type or interface without the
typekeyword.Amaro has nothing to do with it.
This is not a parsing error which is all amaro does.
Check in your code where you are importing
Transactionand change it totype Transaction@JakobJingleheimer can your codemod fix this?
Ethan-Arrowood commentedon Jan 14, 2025
Yes the solution is quite easy and not hard to fix. My point of the issue is that why is this syntax error not stating which file the issue is coming from? If its not amaro, would this be a Node.js loader thing? Where might the best place for this issue be?
Ethan-Arrowood commentedon Jan 14, 2025
Here is another example:
Like yes I can search-replace here to find where these are, but also its a bit of a chore (and can be misleading) in a large code base. I'd rather these errors just contain the file path at least.
marco-ippolito commentedon Jan 14, 2025
Yeah those are node core issues, we might have to trim the stacktrace. Amaro just throws an errors, the caller (Node) is responsible for stacktrace.
JakobJingleheimer commentedon Jan 15, 2025
Yes, I think so
https://github.com/nodejs/userland-migrations/tree/main/recipes/correct-ts-specifiers
The publication to codemod is not quite working yet, but you can run it via node like
$ node path/to/correct-ts-specifiers/src/workflow.tsYou'll need to install correct-ts-specifiers' deps
JakobJingleheimer commentedon Jan 15, 2025
For this, you need a different userland-migration (currently WIP): nodejs/userland-migrations#21
marco-ippolito commentedon Jan 27, 2025
Also typechecker should warn you if you use verbatimModuleSyntax
[-]Feedback: Provide more information when there is a SyntaxError[/-][+]Provide more information when there is a SyntaxError[/+]marco-ippolito commentedon Jan 30, 2025
Moving this issue to nodejs/node, it refs swc-project/swc#9884.
I'm planning to include the location in the file where the error is generated.
marco-ippolito commentedon Mar 26, 2025
This PR will fix the issue #57598 as the filename and line will be correctly included in the error
module: improve typescript error message format
deps: update amaro to 0.5.0
1 remaining item
deps: update amaro to 0.5.0
module: improve typescript error message format
deps: update amaro to 0.5.0
module: improve typescript error message format
module: improve typescript error message format
deps: update amaro to 0.5.0