编译H5提示,提示找不到'@tarojs/components', 小程序能正常编译
-
已经在GITHUB上提了一个ISSUE了
https://github.com/NervJS/taro/issues/3337我的需求是
因小程序的画布支持很多BUG,我就打算另外在H5页面中实现画布相关的功能,再由小程序的WEBVIEW包进来使用.
为了保证相同的风格,我决定另外的H5页面的工程,也采用TARO来编译,也用到了TARO-UI的组件,但是尴尬的是,编译H5的时候,提示找不到'@tarojs/components'
从.temp文件夹中看到的编译结果文件来看,确实没有把@tarojs相关的代码拷贝进来(小程序会有个npm文件夹,里边是依赖的一些东西),所以这个.temp只是临时使用的,如果编译正常,最后会把编译好包含taro内容的文件一并扔到dist目录中么?(猜测)我的备选方案
如果taro编译H5一时解决不了,我的备选方案就是使用标准版的create-react-app来建立一个普通的react工程,那就会引入一个新话题,如何在普通的react工程中,使用taro以及taro-ui组件,不知道有没有这样的专题介绍?
-
这是通过taro init test创建的一个干净的工程,使用的是云开发模板,然后yarn install相关依赖后,直接执行npm run build:h5提示报错的情况,看起来情况有些相似啊
taro init test 👽 Taro v1.3.0-beta.6 Taro即将创建一个新项目! Need help? Go and open issue: https://github.com/NervJS/taro/issues/new ? 请输入项目介绍! ? 是否需要使用 TypeScript ? Yes ? 请选择 CSS 预处理器(Sass/Less/Stylus) Less ? 请选择模板 云开发模板 创建项目 test 成功! 请进入项目目录 test 开始工作吧!😝 PS D:\projects\tarotest> cd test PS D:\projects\tarotest\test\client> yarn install ...... PS D:\projects\tarotest\test\client> npm run build:h5 > test@1.0.0 build:h5 D:\projects\tarotest\test\client > taro build --type h5 👽 Taro v1.3.0-beta.6 开始编译项目 test 创建 发现文件 src\app.less 创建 发现文件 src\app.tsx 创建 发现文件 src\components\login\index.weapp.tsx 创建 发现文件 src\pages\index\index.less 创建 发现文件 src\pages\index\index.tsx 🙅 Failed to compile. ./.temp/pages/index/index.js Module not found: Can't resolve '../../components/login/index' in 'D:\projects\tarotest\test\client\.temp\pages\index' npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! test@1.0.0 build:h5: `taro build --type h5` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the test@1.0.0 build:h5 script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\Kent\AppData\Roaming\npm-cache\_logs\2019-06-06T03_26_49_162Z-debug.log
-
我开始以为是因为我选择的是云开发模板的原因,后来我又换成默认模板又试了一次,这次的报错就和我之前的一样了,找不到'@tarojs/components'
PS D:\projects\tarotest> taro init test2 👽 Taro v1.3.0-beta.6 Taro即将创建一个新项目! Need help? Go and open issue: https://github.com/NervJS/taro/issues/new ? 请输入项目介绍! ? 是否需要使用 TypeScript ? Yes ? 请选择 CSS 预处理器(Sass/Less/Stylus) Less ? 请选择模板 默认模板 ✔ 创建项目: test2 ✔ 创建配置目录: test2/config ✔ 创建源码目录: test2/src ✔ 创建页面目录: test2/src/pages ✔ 创建页面 JS 文件: test2/src/pages/index/index.tsx ✔ 创建页面 LESS 文件: test2/src/pages/index/index.less ✔ 创建文件: test2/src/app.tsx ✔ 创建文件: test2/src/app.less ✔ 创建文件: test2/src/index.html ✔ 创建文件: test2/config/index.js ✔ 创建文件: test2/config/dev.js ✔ 创建文件: test2/config/prod.js ✔ 创建文件: test2/.editorconfig ✔ 创建文件: test2/.gitignore ✔ 创建文件: test2/package.json ✔ 创建文件: test2/.eslintrc ✔ 创建文件: test2/project.config.json 创建项目 test2 成功! 请进入项目目录 test2 开始工作吧!😝 PS D:\projects\tarotest> cd test2 PS D:\projects\tarotest\test2> npm run build:h5 > test2@1.0.0 build:h5 D:\projects\tarotest\test2 > taro build --type h5 👽 Taro v1.3.0-beta.6 开始编译项目 test2 创建 发现文件 src\app.less 创建 发现文件 src\app.tsx 创建 发现文件 src\index.html 创建 发现文件 src\pages\index\index.less 创建 发现文件 src\pages\index\index.tsx 🙅 Failed to compile. ./.temp/pages/index/index.js Module not found: Can't resolve '@tarojs/components' in 'D:\projects\tarotest\test2\.temp\pages\index' npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! test2@1.0.0 build:h5: `taro build --type h5` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the test2@1.0.0 build:h5 script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\Kent\AppData\Roaming\npm-cache\_logs\2019-06-06T03_44_59_037Z-debug.log
-
删除node_modules文件夹,重新安装一下项目依赖吧
-
不得行哦
而且我后边测试的两个工程都是新建立的,新安装的依赖,按说应该不存在问题啊.有没什么办法看到详细的错误内容,类似webpack --display-error-details之类的
-
有可能我自己环境的问题吧,我切到UBUNTU系统下,倒是能正常编译
我为了节省系统盘的开销,把YARN的cache和global移到另外的盘符了.
平时用起来也没啥问题,不知道是不是taro有什么特殊用法,不能应对我这种使用方式.
我正考虑要不要重新安装yarn,把全局安装的包还是扔回去
这是我的.yarnrcregistry "https://registry.yarnpkg.com" "--global-folder" "D:\\YarnGlobal\\Data\\global" cache-folder "d:\\YarnCache" disturl "https://npm.taobao.org/dist" global-folder "D:\\YarnGlobal\\Data\\global" lastUpdateCheck 1559741915878 prefix "D:\\YarnGlobal" "registry=https://registry.yarnpkg.com" true sass_binary_site "https://npm.taobao.org/mirrors/node-sass"
补充
经过重新安装yarn,让全局目录恢复回系统盘,然后又重新安装@tarojs/cli后, 编译成功了,汗...
-
emmmmm...这个情况是第一次见了..