【发布时间】:2016-03-02 07:10:03
【问题描述】:
环境: node@5.70 npm@3.75 browserify@13.0.0 babelify@7.2.0
尝试构建与 npm@2 和 babelify@6 一起使用的应用,但在升级到 npm@3 和 babelify@7 时遇到问题。请允许我尝试解释问题。
在
app/node_modules中,我通过npm install安装了模块,并通过npm link符号链接了本地模块。本地模块在其
package.json中指定了 browserify 转换,例如 -
},
"devDependencies": {
"babel-preset-es2015": "^6.5.0",
"babelify": "^7.2.0"
},
"browserify": {
"transform": [
[
"babelify",
{
"presets": [
"es2015"
]
}
]
]
}
尝试构建我得到错误:
"Browserify Error: Couldn't find preset "es2015" relative to directory"
npm 3 已经扁平化了依赖树,所以符号链接模块需要的 babel-preset-es2015 在 app 的 node_modules 中。根据@substack here 的解释和这个例子here browserify 应该从符号链接模块向上走树到app 并在那里签入node_modules,但它似乎没有这样做。
我的目录布局如下:
~/projects
|-- app
|-- entry.js (this file can see babel-preset just fine)
|-- node_modules
|-- babel-preset-es2015
|-- my-module (symlink pointing at ~/projects/modules-shared/my-module)
|-- index.js (we want babelify to transform this file)
|-- modules-shared
|-- my-module
如果我在modules-shared 文件夹中安装babel-preset-es2015,browserify 会找到预设。
【问题讨论】:
-
您的问题解决了吗?
标签: javascript node.js npm browserify babeljs