[英]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.
我曾经遇到这个问题。
yarn install
if you had installed yarn yarn install
更新到节点版本11.10.0
(当前版本)对我11.10.0
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.