Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

When compiling this, babel throws error

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.

Is the problem node_modules? Because in demo directory, the babel and anything else is in node_modules, so I can import any file I like. But src/tap.js has no such parent or sibling directory like node_modules, so it will trigger this error.

like image 780
qiuyuntao Avatar asked May 15 '16 16:05

qiuyuntao


4 Answers

Updating to node version 11.10.0 (Current Version) worked for me.

like image 56
Tony Tai Nguyen Avatar answered Oct 14 '22 15:10

Tony Tai Nguyen


I just installed core-js and it worked.

like image 37
VimLeSai Avatar answered Nov 03 '22 18:11

VimLeSai


Try to install babel-loader and babel-core as dev-dependency:

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

Also you need to update your .babelrc

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

It works good for me. Good luck ;)

like image 4
Hristo Eftimov Avatar answered Nov 03 '22 17:11

Hristo Eftimov


Maybe you did not install core-js. I used to meet this problem.

  • First, delete your node_modules directory contents
  • Second, execute yarn install if you had installed yarn
  • Third, check your webpack version and babel-loader version, webpack 1.x can must be related to babel-loader 6.x
like image 2
lebron Avatar answered Nov 03 '22 18:11

lebron