本文介绍了找不到模块:错误:无法解析“core-js/es6"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我在构建过程中遇到了与 React 应用相关的问题.

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

我总是收到以下错误:

未找到模块:错误:无法解析core-js/es6"

如果我在 polyfill.js 中使用它:

if I use this in a polyfill.js:

导入'core-js/es6';

那是我的 package.json:

That is my package.json:

{
  "name": "test",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "private": true,
  "devDependencies": {
    "@babel/core": "^7.4.0",
    "@babel/preset-env": "^7.4.2",
    "@babel/preset-react": "^7.0.0",
    "@babel/runtime": "^7.4.2",
    "babel-loader": "^8.0.5",
    "babel-preset-es2015": "^6.24.1",
    "copy-webpack-plugin": "^5.0.2",
    "css-hot-loader": "^1.4.4",
    "eslint": "5.15.3",
    "eslint-config-airbnb": "^17.1.0",
    "eslint-loader": "^2.1.2",
    "eslint-plugin-import": "2.16.0",
    "eslint-plugin-jsx-a11y": "6.2.1",
    "eslint-plugin-react": "7.12.4",
    "file-loader": "^3.0.1",
    "node-sass": "^4.11.0",
    "prettier": "^1.16.4",
    "react-hot-loader": "4.8.0",
    "sass-loader": "^7.1.0",
    "webpack": "^4.29.6",
    "webpack-cli": "^3.3.0",
    "webpack-dev-server": "^3.2.1"
  },
  "dependencies": {
    "axios": "^0.18.0",
    "core-js": "^3.0.0",
    "prop-types": "^15.7.2",
    "react": "^16.8.5",
    "react-dom": "^16.8.5",
    "react-redux": "^6.0.1",
    "react-string-replace": "^0.4.1",
    "redux": "^4.0.1",
    "slick-carousel": "^1.8.1"
  },
  "scripts": {
    "dev": "webpack-dev-server --hot",
    "build": "webpack --colors --profile --progress --env.mode production",
    "lint": "eslint ./src/ --ext .js,.jsx"
  }
}

有人可以帮忙吗?

推荐答案

最终在 projectpathsrcpolyfill.js 中有一个名为 polyfill.js 的文件该文件只包含这一行:import 'core-js'; 这个 polyfills 不仅是 es-6,而且是自 3.0.0 版本以来使用 core-js 的正确方法.

Ended up to have a file named polyfill.js in projectpathsrcpolyfill.jsThat 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.

我将 polyfill.js 添加到我的 webpack-file 条目属性中,如下所示:

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

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

完美运行.

我还在这里找到了更多信息:https://github.com/zloirock/core-js/issues/184

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

图书馆作者 (zloirock) 声称:

The library author (zloirock) claims:

ES6 几乎改变了 ES5 中添加的所有特性的行为,所以 core-js/es6入口点几乎包括所有这些.另外,正如你所写的,它是修复损坏的浏览器实现所必需的.

(引用 https://github.com/zloirock/core-js/issues/184 来自 zloirock)

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

所以我认为 import 'core-js'; 就好了.

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

这篇关于找不到模块:错误:无法解析“core-js/es6"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 12:07