vuejs / vue-cli

🛠️ webpack-based tooling for Vue.js Development
https://cli.vuejs.org/
MIT License
29.76k stars 6.33k forks source link

Error "Cannot find module 'core-js/modules/es.typed-array.at.js' from ..." when executing Jest unit tests after upgrading from v5.0.0-beta.7 to v5.0.0-rc.0 #6830

Open sceee opened 3 years ago

sceee commented 3 years ago

Version

5.0.0-rc.0

Environment info

  System:
    OS: Windows 10 10.0.19043
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  Binaries:
    Node: 14.18.1 - C:\Program Files\nodejs\node.EXE
    Yarn: Not Found
    npm: 6.14.15 - ~\AppData\Roaming\npm\npm.CMD
  Browsers:
    Chrome: 95.0.4638.69
    Edge: Spartan (44.19041.1266.0), Chromium (95.0.1020.44)
  npmPackages:
    @fortawesome/vue-fontawesome: ^2.0.6 => 2.0.6
    @vue/babel-helper-vue-jsx-merge-props:  1.2.1
    @vue/babel-helper-vue-transform-on:  1.0.2
    @vue/babel-plugin-jsx:  1.1.1
    @vue/babel-plugin-transform-vue-jsx:  1.2.1
    @vue/babel-preset-app:  5.0.0-rc.0
    @vue/babel-preset-jsx:  1.2.4
    @vue/babel-sugar-composition-api-inject-h:  1.2.1
    @vue/babel-sugar-composition-api-render-instance:  1.2.4
    @vue/babel-sugar-functional-vue:  1.2.2
    @vue/babel-sugar-inject-h:  1.2.2
    @vue/babel-sugar-v-model:  1.2.3
    @vue/babel-sugar-v-on:  1.2.3
    @vue/cli-overlay:  5.0.0-rc.0
    @vue/cli-plugin-babel: ^5.0.0-rc.0 => 5.0.0-rc.0
    @vue/cli-plugin-e2e-cypress: ^5.0.0-rc.0 => 5.0.0-rc.0
    @vue/cli-plugin-eslint: ^5.0.0-rc.0 => 5.0.0-rc.0
    @vue/cli-plugin-router: ^5.0.0-rc.0 => 5.0.0-rc.0
    @vue/cli-plugin-typescript: ^5.0.0-rc.0 => 5.0.0-rc.0
    @vue/cli-plugin-unit-jest: ^5.0.0-rc.0 => 5.0.0-rc.0
    @vue/cli-plugin-vuex: ^5.0.0-rc.0 => 5.0.0-rc.0
    @vue/cli-service: ^5.0.0-rc.0 => 5.0.0-rc.0
    @vue/cli-shared-utils:  5.0.0-rc.0
    @vue/component-compiler-utils:  3.3.0
    @vue/eslint-config-prettier: ^6.0.0 => 6.0.0
    @vue/eslint-config-typescript: ^9.0.1 => 9.0.1
    @vue/test-utils: ^1.2.2 => 1.2.2
    @vue/vue2-jest: ^27.0.0-alpha.3 => 27.0.0-alpha.3
    @vue/web-component-wrapper:  1.3.0
    bootstrap-vue: ^2.21.2 => 2.21.2
    eslint-plugin-vue: ^8.0.3 => 8.0.3
    jest-serializer-vue:  2.0.2
    portal-vue:  2.1.7
    typescript: ^4.4.4 => 4.4.4
    vue: ^2.6.14 => 2.6.14
    vue-async-computed: ^3.9.0 => 3.9.0
    vue-cli-webpack:  1.0.0
    vue-eslint-parser:  8.0.1
    vue-functional-data-merge:  3.1.0
    vue-head: ^2.2.0 => 2.2.0
    vue-hot-reload-api:  2.3.4
    vue-i18n: ^8.26.7 => 8.26.7
    vue-jest: ^3.0.7 => 3.0.7
    vue-loader:  16.8.3 (15.9.8)
    vue-router: ^3.5.3 => 3.5.3
    vue-style-loader:  4.1.3
    vue-template-compiler: ^2.6.14 => 2.6.14
    vue-template-es2015-compiler:  1.9.1
    vuex: ^3.6.2 => 3.6.2
  npmGlobalPackages:
    @vue/cli: Not Found

Steps to reproduce

Unfortunately, I don't know how to reproduce this.

What is expected?

Unit tests can be executed successfully as they can with v5.0.0-beta.7.

What is actually happening?

Some tests fail with the following error message:

FAIL tests/unit/views/ourtest.spec.ts
  ● Test suite failed to run

    Cannot find module 'core-js/modules/es.typed-array.at.js' from '../shared/functions/any/src/folder/SomeShared.ts'

This happens only with some specific tests after upgrading from v5.0.0-beta.7 to v5.0.0-rc.0.

sceee commented 2 years ago

I could further trace down where this issue results from.

It seems this is caused by dependency conflict between different core-js versions caused by the project structure.

The project structure is as follows:

In project1's tsconfig.json, the path to SomeShared.ts from project2 is included via:

"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "../project2/functions/shared/**/*.ts", "tests/**/*.ts", "tests/**/*.tsx"],

The intention here is to just include some shared files from one central location (they are also used in another project).

So now, what happened was that the versions of core-js got out of sync:

And it seems that jest somehow tries to resolve core-js from node_modules 2" when executing the unit tests ofproject1(instead of resolving it fromnode_modules 1`).

Is jest somehow incorrectly configured for this setup?

A workaround is to install core-js in the same version in project2. Then the unit tests work again but it feels incorrect that jest (executed by vue-cli) tries to resolve core-js from project2 instead of project1 when the unit tests of project1 are executed.

Can this somehow be configured that it just takes the node_modules from the own project?

If that's no vue-cli issue, please let me know as I'm not ultimately sure where this comes from (whether it's from @vue/cli-plugin-unit-jest/presets/typescript-and-babel, jest, @vue/cli or an incorrect configuration).

Any hint is appreciated!

pattrickrice commented 2 years ago

Any luck? I'm encountering this as well

dlodeprojuicer commented 2 years ago

I had the same problem. Updating core-js to 3.22.2 helped fix the issue.