Can't import .mjs modules in the main process
See original GitHub issueDescribe the bug
Some libraries include Ecmascript Modules as .mjs files, it is impossible to import them.
./node_modules/node-fetch/lib/index.mjs 496:11-22
Can\'t import the named export \'PassThrough\' from non EcmaScript module (only default export is available) at HarmonyImportSpecifierDependency._getErrors
(/Users/totominc/Desktop/Git/poe-mapper-assistant/node_modules/webpack/lib/dependencies/HarmonyImportSpecifierDependency.js:90:6)
at HarmonyImportSpecifierDependency.getErrors (/Users/totominc/Desktop/Git/poe-mapper-assistant/node_modules/webpack/lib/dependencies/HarmonyImportSpecifierDependency.js:68:16)
at Compilation.reportDependencyErrorsAndWarnings (/Users/totominc/Desktop/Git/poe-mapper-assistant/node_modules/webpack/lib/Compilation.js:1334:22)
at Compilation.finish (/Users/totominc/Desktop/Git/poe-mapper-assistant/node_modules/webpack/lib/Compilation.js:1136:9)
at hooks.make.callAsync.err (/Users/totominc/Desktop/Git/poe-mapper-assistant/node_modules/webpack/lib/Compiler.js:545:17)
at _err0 (eval at create (/Users/totominc/Desktop/Git/poe-mapper-assistant/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:11:1)
at _addModuleChain (/Users/totominc/Desktop/Git/poe-mapper-assistant/node_modules/webpack/lib/Compilation.js:1064:12)
at processModuleDependencies.err (/Users/totominc/Desktop/Git/poe-mapper-assistant/node_modules/webpack/lib/Compilation.js:980:9)
at process._tickCallback (internal/process/next_tick.js:61:11)
@ ./src/background.ts\n @ multi ./src/background.ts
To Reproduce
yarn add node-fetch && yarn add @types/node-fetch -D
import fetch from 'node-fetch';
fetch('https://google.fr')
.then(response => console.log(response))
.then(body => console.log(body));
yarn serve:electron
Expected behavior
It should import node-fetch successfully, same for all .ejs modules.
Environment (please complete the following information):
- OS and version: Mac OS X 10.13.6
- Node version: 10.8.0
- npm version: 6.2.0
- yarn version (if used): 1.9.4
- vue-cli-plugin-electron-builder version: latest
- other vue plugins used: typescript
- custom config for vcp-electron-builder: none
- (if possible) link to your repo: repo private, sorry
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:10 (5 by maintainers)
Top Results From Across the Web
How to use MJS files in Node.js? - DEV Community
Learn how to import and export from MJS files in Node.js applications. ... SyntaxError: Cannot use import statement outside a module ...
Read more >import stuff from mjs file into js file OR how to use require in ...
Write a little wrapper to redefine require in ESM code. Use import() (dynamic import) in your CJS to import ESM code.
Read more >module-not-found - Next.js
A module not found error can occur for many different reasons: The module you're trying to import is not installed in your dependencies;...
Read more >Module Methods - webpack
The ES2015 Loader spec defines import() as method to load ES2015 modules dynamically on runtime. if (module.hot) { import('lodash ...
Read more >Modules • JavaScript for impatient programmers (ES2022 ...
Entities that are not exported are private to a module and can't be accessed from outside. 27.6.2 Named imports #. Module main.mjs has...
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 Free
Top 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

The issue seems to be a lot more complex and not anymore related to
.mjsmodules, setting the following config is working fine:The issue I have now is kinda related to
node-fetchorwebpack, it is exactly the same problem as here.I’m closing the issue since
.mjsfiles are successfully imported, and I will look to use another HTTP fetch module.No, I set the externals manually. It is much faster to bundle with webpack so I only externalize native deps. I can’t always check if a dep is native so you may have to list it manually.