This repository was archived by the owner on Jun 3, 2021. It is now read-only.
This repository was archived by the owner on Jun 3, 2021. It is now read-only.
when use command weex compile case error /node_modules/weex-ui/index.js Module build failed: Error: Cannot find module 'babel-core' #137
Closed
Description
根据官方命令安装环境
brew install node
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install -g weex-toolkit@latest
然后环境为
然后weex create UUU
然后进入项目
npm i weex-ui@latest -S
npm i babel-plugin-component babel-preset-stage-0 -D
修改文件.babelrc
{
"presets": ["es2015", "stage-0"],
"plugins": [
[
"component",
{
"libraryName": "weex-ui",
"libDir": "packages",
"style": false
}
]
]
}
导入组件
<script>
import { WxcLightbox } from 'weex-ui';
export default {
components: {
WxcLightbox
},
....
使用组件
<template>
<div class="container">
<wxc-lightbox
height="100"
:show="show"
:image-list="imageList"
@wxcLightboxOverlayClicked="wxcLightboxOverlayClicked">
</wxc-lightbox>
...
然后执行命令weex compile src /usr/local/var/www
用来把js文件放到nginx上,结果报错
试了npm装,cnpm装,都报错
/node_modules/weex-ui/index.js Module build failed: Error: Cannot find module 'babel-core'
Activity
tw93 commentedon Jan 27, 2018
Try it https://alibaba.github.io/weex-ui/#/cn/with-weex-toolkit
songxing10000 commentedon Jan 28, 2018
@tw93 所有操作都是按那个文档来的,
npm run serve
能界面正常,为啥执行命令weex compile src /usr/local/var/www用来把js文件放到nginx上,就会提示/node_modules/weex-ui/index.js Module build failed: Error: Cannot find module 'babel-core'
呢
tw93 commentedon Jan 28, 2018
Try
songxing10000 commentedon Jan 31, 2018
已解决,将文件

/usr/local/lib/node_modules
下的weex-toolkit
反复删除,反复执行npm install -g weex-toolkit@latest
就正常了,因为之前已经在项目里执行过了命令npm i
npm i weex-ui@latest -S
npm i babel-plugin-component babel-preset-stage-0 -D
同时修改.babelrc,所以命令npm install -g weex-toolkit@latest
是关键liangklfangl commentedon Mar 14, 2018
这个反复两个字用的好,到底是多少次算反复?
liangklfangl commentedon Mar 14, 2018
其实解决方案在这里。因为weex-toolkit全局安装的时候将babel-core设置了devDependencies,所以导致全局安装的时候并不会主动安装它,所以找不到这个模块,你可以看看weex-toolkit的package.json。建议官方修复下这个问题~~~
songxing10000 commentedon Jun 5, 2018
又报这个错了
weex build failed: Error: Cannot find module \'babel-core\'\n at
,解决方案还是
将文件
/usr/local/lib/node_modules
下的weex-toolkit
删除,执行
npm install -g weex-toolkit@latest
就正常了,然后 删除项目里的
node_modules
,然后执行
cnpm install
,并没有执行npm i npm i weex-ui@latest -S
和npm i babel-plugin-component babel-preset-stage-0 -D
也是编译成功的