[Taro FAQs] Taro inconsistency version cause an error: Module not found: Can't resolve 'undefined'

Inconsistency between the Taro CLI and the project’s dependency version

Taro is an open cross-terminal and cross-framework solution that supports the use of React/Vue/Nerv and other frameworks to develop applications such as WeChat/JD/Baidu/Alipay/ByteDance/QQ applet/H5.


Keep the Taro CLI version consistent with the version of Taro related dependencies in the project

Please always pay attention to keep the Taro CLI version consistent with the version of Taro related dependencies in the project.


The inconsistency between the CLI and the project’s dependency version is one of the sources of many problems. For example, if the Taro CLI version is 3.0.8, then the version of Taro-related dependencies must also be 3.0.8. Taro-related package names can be known from this list - https://nervjs.github.io/taro/docs/CONTRIBUTING/#taro-%E7%BB%84%E6%88%90, and the specific dependency versions can be obtained by using the taro info command or through package.json Know.

Module not found: Can’t resolve ‘undefined’

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$ npm run build:weapp
...
👽 Taro v3.0.25
...
🙅 编译失败. 4/22/2021, 2:29:08 PM

./src/app.ts
Module not found: Can't resolve 'undefined' in '/Users/cloudolife/WorkSpaces/col-taro/taro-example/src'


监听文件修改中...

./src/app.ts
Module not found: Error: Can't resolve 'undefined' in '/Users/cloudolife/WorkSpaces/col-taro/taro-example/src'
resolve 'undefined' in '/Users/cloudolife/WorkSpaces/col-taro/taro-example/src'
Parsed request is a module
using description file: /Users/cloudolife/WorkSpaces/col-taro/taro-example/package.json (relative path: ./src)
resolve as module
/Users/cloudolife/WorkSpaces/col-taro/taro-example/src/node_modules doesn't exist or is not a directory
/Users/cloudolife/WorkSpaces/col-taro/node_modules doesn't exist or is not a directory
/Users/cloudolife/WorkSpaces/node_modules doesn't exist or is not a directory
/Users/cloudolife/node_modules doesn't exist or is not a directory
/Users/node_modules doesn't exist or is not a directory
/node_modules doesn't exist or is not a directory
looking for modules in /Users/cloudolife/WorkSpaces/col-taro/taro-example/node_modules

Check Taro version in ‘package.json’.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$ cat package.json
...
"dependencies": {
...
"@tarojs/cli": "^3.1.4",
"@tarojs/components": "3.1.4",
"@tarojs/react": "3.1.4",
"@tarojs/runtime": "3.1.4",
"@tarojs/taro": "3.1.4",
...
},
"devDependencies": {
...
"@tarojs/mini-runner": "3.1.4",
"@tarojs/webpack-runner": "3.1.4",
...
}
...

If you find inconsistencies, you can use the Taro upgrade commands taro update self [version number] and taro update project [version number] to upgrade the CLI and project dependencies to the specified version respectively;

Upgrade @tarojs/cli to 3.1.4+ version.

1
2
3
$ taro update self 3.1.4

$ taro update project 3.1.4

Or you can manually install the corresponding version of the CLI and modify package.json Depend on the version number, and then reinstall the dependency to solve it.

1
2
3
$ npm install @tarojs/[email protected]

$ npm i

Then, run build:weapp to rebuild it.

1
$ npm run build:weapp

References

[1] Taro | 多端统一开发解决方案 - https://taro.jd.com/

[2] GitHub - NervJS/taro: 开放式跨端跨框架解决方案,支持使用 React/Vue/Nerv 等框架来开发微信/京东/百度/支付宝/字节跳动/ QQ 小程序/H5/React Native 等应用。 https://taro.zone/ - https://github.com/nervjs/taro

[3] 保持 CLI 的版本与各端依赖版本一致 | 安装及使用 | Taro 文档 - https://taro-docs.jd.com/taro/docs/GETTING-STARTED#%E4%BF%9D%E6%8C%81-cli-%E7%9A%84%E7%89%88%E6%9C%AC%E4%B8%8E%E5%90%84%E7%AB%AF%E4%BE%9D%E8%B5%96%E7%89%88%E6%9C%AC%E4%B8%80%E8%87%B4

[4] 将 Taro CLI 版本与项目中 Taro 相关依赖的版本保持一致 | Taro 版本升级权威指南 | Taro 文档 - https://taro-docs.jd.com/taro/blog/2020-09-01-taro-versions#%E5%B0%86-taro-cli-%E7%89%88%E6%9C%AC%E4%B8%8E%E9%A1%B9%E7%9B%AE%E4%B8%AD-taro-%E7%9B%B8%E5%85%B3%E4%BE%9D%E8%B5%96%E7%9A%84%E7%89%88%E6%9C%AC%E4%BF%9D%E6%8C%81%E4%B8%80%E8%87%B4