简体   繁体   English

Babel编译错误:找不到模块core-js / library / fn / get-iterator

[英]Babel compile error: Cannot find module core-js/library/fn/get-iterator

This is my directory structure: 这是我的目录结构:

├───demo
│   ├───entry
│   │   ├───index.js
│   │   ├───tap.js
│   │   └───util.js
│   ├───node_modules
│   ├───index.html
│   ├───package.json
│   └───webpack.config.js
├───src
│   ├───tap.js
│   └───util.js
├───index.js
└───package.json

In demo/entry/index.js I have demo/entry/index.js我有

import tap from '../../src/tap';

When compiling this, babel throws error 编译时,babel抛出错误

ERROR in ../src/tap.js
Module build failed: Error: Cannot find module 'core-js/library/fn/get-iterator'

But it works if I import like this 但是如果我这样导入就可以了

import tap from './tap';

The file ./tap.js and ../../src/tap are the same. 文件./tap.js../../src/tap相同。

Is the problem node_modules ? 问题是node_modules吗? Because in demo directory, the babel and anything else is in node_modules , so I can import any file I like. 因为在demo目录中,babel和其他所有内容都在node_modules ,所以我可以import任何我喜欢的文件。 But src/tap.js has no such parent or sibling directory like node_modules , so it will trigger this error. 但是src/tap.js没有像node_modules这样的父目录或兄弟目录,因此它将触发此错误。

Try to install babel-loader and babel-core as dev-dependency: 尝试将babel-loader和babel-core安装为dev-dependency:

npm install babel-core babel-loader --save-dev

Also you need to update your .babelrc 另外,您需要更新您的.babelrc

{ 
    "presets" : ["es2015", "react"]
}

It works good for me. 对我有用。 Good luck ;) 祝好运 ;)

我刚安装了core-js,它就起作用了。

Maybe you did not install core-js. 也许您没有安装core-js。 I used to meet this problem. 我曾经遇到这个问题。

  • First, delete your node_modules directory contents 首先,删除您的node_modules目录内容
  • Second, execute yarn install if you had installed yarn 其次,如果您已经安装了纱线,请执行yarn install
  • Third, check your webpack version and babel-loader version, webpack 1.x can must be related to babel-loader 6.x 第三,检查您的webpack版本和babel-loader版本,webpack 1.x必须与babel-loader 6.x相关

更新到节点版本11.10.0 (当前版本)对我11.10.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在本机反应中找不到模块“core-js/fn/array/values” - Cannot find module 'core-js/fn/array/values' in react native 无法解析模块'babel-runtime / core-js / object / define-properties' - Cannot resolve module 'babel-runtime/core-js/object/define-properties' 未找到此依赖项:* core-js/fn/symbol - This dependency was not found: * core-js/fn/symbol 模块构建失败:错误:找不到模块'@ babel / core' - Module build failed: Error: Cannot find module '@babel/core' ERROR in找不到模块'babel-core'。使用react.js,webpack和express服务器 - ERROR in Cannot find module 'babel-core'. using react.js, webpack, and express server Babel无法找到模块核心/启动Node.js - Babel cannot find module core/splash Node.js 找不到'core-js'的类型定义文件 - Cannot find type definition file for 'core-js' 如何解决找不到模块:无法在 Material-UI 中解析“@babel/runtime/core-js/map” - How to solve Module not found: Can't resolve '@babel/runtime/core-js/map' in Material-UI 找不到模块“ babel-core”,但已安装@ babel / core - Cannot find module 'babel-core' but @babel/core is installed 模块构建失败(来自./node_modules/babel-loader/lib/index.js):错误:找不到模块'babel-core' - Module build failed (from ./node_modules/babel-loader/lib/index.js): Error: Cannot find module 'babel-core'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM