Module not found: Error: Can't resolve 'core-js/es6'

后端 未结 9 1122
轻奢々
轻奢々 2020-12-12 14:49

I\'ve got a problem with my build process in relation to my React app.

I always get the following error:

Module not found: Error: Can\'t resolve \'co

相关标签:
9条回答
  • 2020-12-12 15:03

    Ended up to have a file named polyfill.js in projectpath\src\polyfill.js That file only contains this line: import 'core-js'; this polyfills not only es-6, but is the correct way to use core-js since version 3.0.0.

    I added the polyfill.js to my webpack-file entry attribute like this:

    entry: ['./src/main.scss', './src/polyfill.js', './src/main.jsx']

    Works perfectly.

    I also found some more information here : https://github.com/zloirock/core-js/issues/184

    The library author (zloirock) claims:

    ES6 changes behaviour almost all features added in ES5, so core-js/es6 entry point includes almost all of them. Also, as you wrote, it's required for fixing broken browser implementations.

    (Quotation https://github.com/zloirock/core-js/issues/184 from zloirock)

    So I think import 'core-js'; is just fine.

    0 讨论(0)
  • 2020-12-12 15:04

    Change all "es6" and "es7" to "es" in your polyfills.ts and polyfills.ts (Optional).

    • From: import 'core-js/es6/symbol';
    • To: import 'core-js/es/symbol';
    0 讨论(0)
  • 2020-12-12 15:11

    Just change "target": "es2015" to "target": "es5" in your tsconfig.json.

    Work for me with Angular 8.2.XX

    Tested on IE11 and Edge

    0 讨论(0)
  • 2020-12-12 15:15

    After Migrated to Angular8, core-js/es6 or core-js/es7 Will not work.

    You have to simply replace import core-js/es/

    For ex.

    import 'core-js/es6/symbol'  
    

    to

    import 'core-js/es/symbol'
    

    This will work properly.

    0 讨论(0)
  • 2020-12-12 15:15

    Sure, I had a similar issue and a simple

    npm uninstall @babel/polyfill --save &&
    npm install @babel/polyfill --save
    

    did the trick for me.

    However, usage of @babel/polyfill is deprecated (according to this comment) so only try this if you think you have older packages installed or if all else fails.

    0 讨论(0)
  • 2020-12-12 15:20

    I found possible answer. You have core-js version 3.0, and this version doesn't have separate folders for ES6 and ES7; that's why the application cannot find correct paths.

    To resolve this error, you can downgrade the core-js version to 2.5.7. This version produces correct catalogs structure, with separate ES6 and ES7 folders.

    To downgrade the version, simply run:

    npm i -S core-js@2.5.7
    

    In my case, with Angular, this works ok.

    0 讨论(0)
提交回复
热议问题