question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

  1. Install a node module that includes files with the .mjs extension such as svelte or acorn.
npm i svelte
  1. Attempt to reference such a node module by its bare module specificer.
import 'svelte';
  1. 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:closed
  • Created 3 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
wessbergcommented, Jul 31, 2020

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 the allowJs 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 😃

0reactions
ggoodmancommented, Jul 31, 2020

Looks like we should be tracking microsoft/typescript#39840.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found