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

qiuyuntao picture qiuyuntao · May 15, 2016 · Viewed 16.4k times · Source

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.

Answer

VimLeSai picture VimLeSai · Mar 18, 2019

I just installed core-js and it worked.