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.

Webpack crashes with Babel transpiled ES6 modules

See original GitHub issue

Webpack started enforcing the presence of file extensions on import/export statements inside ES6 modules (https://github.com/webpack/webpack/issues/11467).

It seems Babel is currently injecting statements that violate this rule while transpiling. The following log is from a fresh install of Ember 3.28.1 with Embroider blueprint, after installing a dependency with ES6 modules and requiring one of them (I’ve redacted the sensible information):

ERROR in …/…/…/PROJECT_PATH/node_modules/@my-scope/my-package/src/auth-client.js 1:0-166 Module not found: Error: Can’t resolve ‘/PROJECT_PATH/node_modules/@embroider/core/node_modules/@babel/runtime/helpers/esm/defineProperty’ in ‘/PROJECT_PATH/node_modules/@my-scope/my-package/src’ Did you mean ‘defineProperty.js’? BREAKING CHANGE: The request ‘/PROJECT_PATH/node_modules/@embroider/core/node_modules/@babel/runtime/helpers/esm/defineProperty’ failed to resolve only because it was resolved as fully specified (probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a ‘.mjs’ file, or a ‘.js’ file where the package.json contains ‘“type”: “module”’). The extension in the request is mandatory for it to be fully specified. Add the extension to the request. @ …/…/…/PROJECT_PATH/node_modules/@my-scope/my-package/src/mixins/token/unauthenticated.js 1:0-50 11:13-23 @ …/…/…/PROJECT_PATH/node_modules/@my-scope/my-package/src/client.js 3:0-66 32:15-27 @ …/…/…/PROJECT_PATH/node_modules/@my-scope/my-package/index.js 1:0-41 1:0-41 @ ./services/my-service.js 2:0-37 @ ./assets/ember-client.js 49:9-41

There are some issues on Babel that revolve around this, but they claim it was fixed by 7.12.0 (https://github.com/babel/babel/issues/12003, https://github.com/babel/babel/issues/12158).

There is a workaround so Webpack doesn’t freak out on incorrect Babel transpiled code. Maybe it’d be good to add it to the default blueprint: https://github.com/webpack/webpack/issues/11467#issuecomment-808618999

Ps.: I can’t disclosure the package code, but it’s just some classes with methods and only two dependencies: buffer and cross-fetch. It works as expected on node.js.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
MrChocolatinecommented, Nov 2, 2021

I don’t get it, the logs you posted were produced by Webpack v5.x. If you were to stick with v4.x this wouldn’t even be an issue as polyfills are included. On a side note, IIRC, ember-auto-import v2.x is backwards compatible, so you shouldn’t have trouble updating it.

Huh, true true… Embroider scenarios, Webpack 5 implied… I am not quite not sure why I said that about Webpack, I have been juggling with Embroider and tests all day so my brain was kind of melting after a while.

Anyway I found a way to fix my initial issue:

https://github.com/peopledoc/ember-reading-time/pull/13/commits/c55b4070223849bf60ab504aed6c5f2e377b96cc

I realise I am squatting your issue sorry, let me know if you want me to create another one so that I stop interfering with yours ✌️ .

0reactions
andsmedeiroscommented, Nov 2, 2021

I don’t get it, the logs you posted were produced by Webpack v5.x. If you were to stick with v4.x this wouldn’t even be an issue as polyfills are included. On a side note, IIRC, ember-auto-import v2.x is backwards compatible, so you shouldn’t have trouble updating it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack fails to transpile module imported from npm package
node_modules /r2d2/src/js/main.js. is not in that folder, so it doesn't get compiled. The easiest fix would be to expand your loader config ...
Read more >
How to transpile ES modules with webpack and Node.js
Learn how webpack interacts with and supports ES modules in this deep dive tutorial on transpilation in Node.js.
Read more >
Create React v18 TypeScript Project with webpack and Babel
Bundle JavaScript with webpack; Introduce React; Transpile and Polyfill to ES5; Add TypeScript ... The key module is @babel/preset-env and core-js .
Read more >
Module Methods - webpack
ES6 (Recommended). Version 2 of webpack supports ES6 module syntax natively, meaning you can use import and export without a tool like babel...
Read more >
The road to native ES6 SPAs - Sean Blanchfield
Let me tell you about my node_modules directory. For a vanilla Vue.js SPA project with recommended webpack/babel build pipeline, configured with ...
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