Skip to content

Cannot find module 'core-js/library/xxx' when import element-ui #2275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task
showmethecode9527 opened this issue Apr 3, 2020 · 14 comments
Open
1 task
Labels
status: core team review Priority issues for the core team to review type: bug Something isn't working

Comments

@showmethecode9527
Copy link

showmethecode9527 commented Apr 3, 2020

  • I confirm that this is an issue rather than a question.

Bug report

Steps to reproduce

# Vue CLI v4.2.3
$ vue create vuepress-test # use preset 'default' or 'Manually select features'
$ cd vuepress-test
$ npm i -S element-ui
$ npm i -D vuepress

Then create docs/README.md, docs/.vuepress/enhanceApp.js

// docs/.vuepress/enhanceApp.js
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

export default ({
  Vue
}) => {
  Vue.use(ElementUI)
}

Then run vuepress dev docs and open the browser's console

What is expected?

build success

What is actually happening?

build error

Other relevant information

  • Output of npx vuepress info in my VuePress project:
  System:
    OS: Windows 10 10.0.18362
    CPU: (4) x64 Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
  Binaries:
    Node: 12.16.0 - D:\nvm_nodejs\node.EXE
    Yarn: Not Found
    npm: 6.13.4 - D:\nvm_nodejs\npm.CMD
  Browsers:
    Edge: 44.18362.449.0
  npmPackages:
    @vuepress/core: Not Found
    @vuepress/theme-default: Not Found
    vuepress: ^1.4.0 => 1.4.0
  npmGlobalPackages:
    vuepress: Not Found
@haoranpb
Copy link
Contributor

haoranpb commented Apr 3, 2020

Hi @showmethecode9527 , thanks for the report.

npm i core-js@2 seems to solve the issue, but I'm not sure if it will break other things

@showmethecode9527
Copy link
Author

Hi @showmethecode9527 , thanks for the report.

npm i core-js@2 seems to solve the issue, but I'm not sure if it will break other things

I changed 3.x to 2.x and it works well, but in an other project, failed to compile:

These dependencies were not found:

* core-js/modules/web.dom-collections.for-each in ./packages/index.js
......

@1ncounter
Copy link

i meet the same problem with you! Are you resolve it?

@showmethecode9527
Copy link
Author

i meet the same problem with you! Are you resolve it?

Use core-js 2.x can resolve it, but my web project needs core-js 3.x, so I'm using core-js 2.x to run docs and core-js 3.x to run my web app.

@boughia
Copy link

boughia commented Apr 29, 2020

This seems to be caused by vuepress's webpack configuration. element-ui requires async-validator 1.x which requires babel-runtime 6.x which requires core-js 2.x, while vuepress depends on core-js 3.x. I installed element-ui after vuepress and my node_modules folder looks like this:

node_modules
----core-js 3.x
----babel-runtime 6.x
--------node_modules
------------core-js 2.x

In file packages/@vuepress/core/lib/node/webpack/createBaseConfig.js, webpack's resolve.modules setting is changed:
Line 52: const modulePaths = getModulePaths()
Line 69: config.resolve.merge(modulePaths)
Line 332-334:

function getModulePaths () {
  return module.paths.concat([path.resolve(process.cwd(), 'node_modules')])
}

I found that the new value does not contain babel-runtime 6.x 's local node_module folder, so module resolution of core-js 2.x would fail for babel-runtime.

I tried changing line 333 to
return module.paths.concat([path.resolve(process.cwd(), 'node_modules'), 'node_modules'])
and it worked for me.

@OvedayBySnow
Copy link

Is there any better way to solve this for me? It seems that I have conflicts with ant-design-vue, but sometimes I don't want to separate them into projects

@superxiaobin
Copy link

npm install [email protected]

succ

@showmethecode9527
Copy link
Author

npm install [email protected]

succ

sometimes it works well, but not all the time.

@superxiaobin
Copy link

npm install [email protected]
succ

sometimes it works well, but not all the time.

when you install [email protected], you must restart npm run dev.

@Nayacco
Copy link

Nayacco commented Sep 16, 2020

Execute this command yarn add [email protected] solved the problem

@andyhuai
Copy link

yarn add [email protected]

Yes, it works!!!!!

@hql7
Copy link

hql7 commented Nov 6, 2020

执行此命令解决了问题yarn add [email protected]

cool

@xgqfrms
Copy link

xgqfrms commented Jan 14, 2021

shit official docs 💩

https://vuepress.vuejs.org/guide/directory-structure.html

image

image

#2764

#2763

solution 1

add the async-validator npm package

$ yarn add [email protected]

#  OR 
$ npm i [email protected]
{

  "devDependencies": {
    "vuepress": "1.5.3"
  },
  "dependencies": {
+  "async-validator": "1.11.5",
    "element-ui": "2.14.1"
  }

}

solution 2

⚠️ do not lock npm version

{

  "devDependencies": {
-   "vuepress": "1.5.3"
+  "vuepress": "^1.5.3"
  },
  "dependencies": {
-  "element-ui": "2.14.1"
+  "element-ui": "^2.14.1"
  }

}

@KunerRick
Copy link

KunerRick commented Aug 12, 2021

This seems to be caused by vuepress's webpack configuration. element-ui requires async-validator 1.x which requires babel-runtime 6.x which requires core-js 2.x, while vuepress depends on core-js 3.x. I installed element-ui after vuepress and my node_modules folder looks like this:

node_modules
----core-js 3.x
----babel-runtime 6.x
--------node_modules
------------core-js 2.x

In file packages/@vuepress/core/lib/node/webpack/createBaseConfig.js, webpack's resolve.modules setting is changed:
Line 52: const modulePaths = getModulePaths()
Line 69: config.resolve.merge(modulePaths)
Line 332-334:

function getModulePaths () {
  return module.paths.concat([path.resolve(process.cwd(), 'node_modules')])
}

I found that the new value does not contain babel-runtime 6.x 's local node_module folder, so module resolution of core-js 2.x would fail for babel-runtime.

I tried changing line 333 to
return module.paths.concat([path.resolve(process.cwd(), 'node_modules'), 'node_modules'])
and it worked for me.

I put this in config.js

module.exports = {
  chainWebpack(config, isServer) {
    if (!isServer) {
       config.resolve.modules.merge(["node_modules"]);
    }
    return config;
  },
  }

Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: core team review Priority issues for the core team to review type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests