Uncaught exception when node_modules includes a .mjs file
See original GitHub issue- Version:
1.2.34
- Rollup Version:
2.23.0
- Typescript Version:
3.9.7
- Operating System and version (if applicable): N/A
- Node Version (if applicable): N/A
- Does it work with
tsc
(if applicable): Yes
Reproduction
- Install a node module that includes files with the .mjs extension such as
svelte
oracorn
.
npm i svelte
- Attempt to reference such a node module by its bare module specificer.
import 'svelte';
- Attempt to generate a bundle.
Expected Behavior
A bundle is generated without error.
Actual Behavior
> rollup -c -w
rollup v2.23.0
bundles src/main.ts → public/build...
[!] (plugin Typescript) TypeError: Cannot read property 'flags' of undefined
node_modules/svelte/index.mjs
TypeError: Cannot read property 'flags' of undefined
at resolveAlias (<REDACTED>/node_modules/typescript/lib/typescript.js:37340:37)
at checkAliasSymbol (<REDACTED>/node_modules/typescript/lib/typescript.js:66174:26)
at checkExportSpecifier (<REDACTED>/node_modules/typescript/lib/typescript.js:66348:13)
at Object.forEach (<REDACTED>/node_modules/typescript/lib/typescript.js:317:30)
at checkExportDeclaration (<REDACTED>/node_modules/typescript/lib/typescript.js:66286:24)
at checkSourceElementWorker (<REDACTED>/node_modules/typescript/lib/typescript.js:66642:28)
at checkSourceElement (<REDACTED>/node_modules/typescript/lib/typescript.js:66473:17)
at Object.forEach (<REDACTED>/node_modules/typescript/lib/typescript.js:317:30)
at checkSourceFileWorker (<REDACTED>/node_modules/typescript/lib/typescript.js:66810:20)
at checkSourceFile (<REDACTED>/node_modules/typescript/lib/typescript.js:66778:13)
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Importing in Node.js: error "Must use import to load ES Module"
To delete the package-lock. json file and the node_modules folder, run npm. I then npm start to solve my problem. Save this answer....
Read more >How to use MJS files in Node.js? - DEV Community
Learn how to import and export from MJS files in Node.js applications. ... To use ES modules, it has to bet set to...
Read more >Node Modules at War: Why CommonJS and ES ... - Code Red
Here's an ESM example where util.mjs sets a default export. Just like in CJS, the default export has no name, but the module...
Read more >Node.js v19.3.0 Documentation
If an uncaught exception occurs during execution of the callback, then after will run after the 'uncaughtException' event is emitted or a domain...
Read more >Modules • JavaScript for impatient programmers (ES2022 ...
Libraries in script files export and import functionality via global variables, ... Module my-math.mjs has two named exports: square and LIGHTSPEED .
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the update! Much appreciated. So, I found the cause of the issue. I simply thought TypeScript supported
.mjs
files, but it doesn’t. I thought theallowJs
flag included and enabled type checking for.mjs
files, but it doesn’t.I’ve fixed it in v1.3.1 and aligned with the behavior of
tsc
. I’ve also written you a message on Twitter about the other issue you mentioned 😃 It has been fixed, but there are two small fixes that needs to be made in your monorepro to avoid type duplication 😃Looks like we should be tracking microsoft/typescript#39840.