- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
在我的 React
npm
模块的开发过程中,我将它与 npm link
符号链接(symbolic link)。完成此操作后,包会正确链接并出现在消费者应用程序 node_modules
中。
该模块公开了一个接口(interface)来创建一个 React
组件。因为我使用 React
、jsx
和 es2015
,所以我使用 babel
将我的模块代码转换为预发布阶段,使用 npm prepublish 钩子(Hook)
。
但是,当我尝试使用 webpack
构建我的消费者应用程序时(即链接它之后),我的包中出现错误:
Module build failed: Error: Couldn't find preset "es2015"
现在有趣的是,如果我在 npm 上发布包,然后从我的消费者应用程序的注册表中 npm install
,构建它,一切正常。
我尝试在我的消费者应用程序中安装 babel-preset-es2015
,但随后它开始提示找不到 babel
:
Module not found: Error: Cannot resolve module 'babel'
同样,如果我从 npm 注册表安装它,一切正常,在构建过程中不会抛出任何错误。
我也试过安装babel-core
、babel-cli
和babel-polyfill
,都无济于事。
我正在到处使用 babel v6.1.x
并且知道所有最近的更改,但是我想我遗漏了一些明显的东西,如果有人可以帮助我,我将不胜感激,因为不断发布模块以测试东西是否有效只是不好的做法。
为了完整起见,这里是代码:
这些是我链接模块的步骤:
cd ~/Sites/me/react-leafbox
npm 链接
cd ~/Sites/me/mapp
npm 链接 react-leafbox
npm 开始
构建后的堆栈跟踪:
ERROR in ../react-leafbox/lib/index.js
Module build failed: Error: Couldn't find preset "es2015"
at OptionManager.mergePresets (/Users/daniel/Sites/me/mapp/node_modules/babel-core/lib/transformation/file/options/option-manager.js:329:17)
at OptionManager.mergeOptions (/Users/daniel/Sites/me/mapp/node_modules/babel-core/lib/transformation/file/options/option-manager.js:289:12)
at OptionManager.addConfig (/Users/daniel/Sites/me/mapp/node_modules/babel-core/lib/transformation/file/options/option-manager.js:223:10)
at OptionManager.findConfigs (/Users/daniel/Sites/me/mapp/node_modules/babel-core/lib/transformation/file/options/option-manager.js:366:16)
at OptionManager.init (/Users/daniel/Sites/me/mapp/node_modules/babel-core/lib/transformation/file/options/option-manager.js:410:12)
at File.initOptions (/Users/daniel/Sites/me/mapp/node_modules/babel-core/lib/transformation/file/index.js:191:75)
at new File (/Users/daniel/Sites/me/mapp/node_modules/babel-core/lib/transformation/file/index.js:122:22)
at Pipeline.transform (/Users/daniel/Sites/me/mapp/node_modules/babel-core/lib/transformation/pipeline.js:42:16)
at transpile (/Users/daniel/Sites/me/mapp/node_modules/babel-loader/index.js:14:22)
at Object.module.exports (/Users/daniel/Sites/me/mapp/node_modules/babel-loader/index.js:83:14)
@ ./src/js/components/App.jsx 2:10-34
添加额外的 babel 相关依赖项后的堆栈跟踪(我认为这不是必需的,因为它们在 react-leafbox 模块中可用):
ERROR in ../react-leafbox/lib/index.js
Module not found: Error: Cannot resolve module 'babel' in /Users/daniel/Sites/me/react-leafbox/lib
@ ../react-leafbox/lib/index.js 8:11-39
我在 MAC OSX El Capitan v10.11.1
上使用 node v5.0.0
和 npm v3.3.6
。我还尝试将 node v4.2.1
与 npm 2.14.7
一起使用,这给了我同样的错误。
最佳答案
我找到了解决问题的方法。我在 webpack docs 中发现了这个:
IMPORTANT: The loaders here are resolved relative to the resource which they are applied to. This means they are not resolved relative the the configuration file. If you have loaders installed from npm and your node_modules folder is not in a parent folder of all source files, webpack cannot find the loader. You need to add the node_modules folder as absolute path to the resolveLoader.root option. (resolveLoader: { root: path.join(__dirname, "node_modules") })
在 webpack.config.js
添加 root
选项后,关于无法解析 babel
的错误消失了。相反,我得到了一个新的说它无法解析 react
。我将它定义为对等依赖项,这让我认为当它在本地找不到它时需要回退,然后我在 docs 中找到了它:
resolve.fallback A directory (or array of directories absolute paths), in which webpack should look for modules that weren’t found in resolve.root or resolve.modulesDirectories.
我在我的消费者应用程序的 webpack.config.js
中结合了这两个选项,并且成功了!
// webpack.config.js
var path = require('path');
module.exports = {
entry: path.resolve(__dirname, 'src/js/index.js'),
output: {
path: path.resolve(__dirname, 'dist'),
filename: "build.js"
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules)/,
loader: 'babel',
query:
{
presets:[ 'react', 'es2015' ]
}
}
]
},
resolve: {
extensions: [ '', '.js', '.jsx' ],
fallback: path.join(__dirname, "node_modules")
},
resolveLoader: {
root: path.join(__dirname, "node_modules")
}
};
我希望这对遇到类似问题的人有所帮助。
Webpack ^2.5.0 更新
移除 resolveLoader
对象并将 resolve.fallback
替换为 resolve.symlinks
设置为 false
:
resolve: {
extensions: [ '', '.js', '.jsx' ],
symlinks: false
}
关于node.js - 使用 npm 链接符号链接(symbolic link) react 模块以进行本地开发会产生错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33711512/
我通常从以下位置获取代码:https://www.w3schools.com .这个代码还有一个 Accordion ; 但是,当我使用链接 -> 到 Accordion 时, Accordion 不
我见过的所有 JNI 指南(例如 JNI runtime linking )都建议我将 JNI 库链接到 libjvm.so: $ gcc -I${JAVA_HOME}/include -c -o t
实现以下目标的正确 URL 格式是什么: 使用 Universal Link 在 iOS 上的另一个应用程序中打开 Google map 应用程序。 根据两个坐标设置目的地:纬度和经度,并让用户选择交
我已经查看了 Microsoft 的 MSDN 和整个网络,但我仍然无法很好地了解它是什么。 这是否意味着已完成的程序在执行期间的不同时间加载 DLL,而不是在启动时一次性加载所有 DLL? 我完全偏
我有一个看起来像这样的 css: .browse-link A:link { color: #F6CA4C; text-decoration: none; } .browse-link
当我点击“产品”链接时,它突然指向#link。我怎样才能使它的外观看起来像滚动然后转到产品?请帮帮我。 vStudy function big(x){
我想在保存之前更改从输入字段中获取的值。 params[:link]['url'] = "www.facebook.com/redbull" 现在我只想将“redbull”放入数据库。以下代码失败,因
我正在使用链表编写程序(真是一场噩梦)。 无论如何,该程序的目的是输入 8 个字符,然后让程序将字符打印回给您,并以相反的顺序打印回字符,当然是使用链表。 到目前为止我已经明白了。它有很多错误(我认为
基本上,我删除了 anchor 按钮,因此链接窗口中不应该有指向 anchor 选项的链接。 有什么方法可以删除该下拉选项 ? 最佳答案 想通了 if ( dialogName == 'link' )
我的本地(和远程)SQL SERVER 2005 管理员都声称“允许链接服务器是一个安全问题”并禁止在此处使用它们。 (哈?) 无论如何,有没有办法在没有链接服务器的情况下做类似的事情? SELE
如果我有: linkedlist1= 1,2,3,4; 和 linkedlist2= 5,6,7; 如果我调用: linkedlist2.set(0,9999) 它会更改为 linkedlist2 =
首先,如果这个问题看起来很愚蠢,我很抱歉,但我仍在学习 React 和 html。所以问题是我的 react 代码中有一个按钮标签,它为我提供了一些关于进入我提供的特定链接的逻辑。我的 Button.
我将制作一个文本 block ,这样如果您单击一个单词,它就会被词汇替代品所替换。 例如“fearful-of-cats”是“ailurophobic”的词汇替代品,因为如果您在任何文本中将后者替换为
我有以下代码 Can you click me? 目标是我可以点击“你能点击我吗”框并转到 google 并在包含 div 的任何其他地方
这是一个案例: 默认情况下,如果我点击#2、#3、#4、#5,我将被重定向到#1。 如果我想在没有 #1 激活的情况下点击输入,我该如何修复 CSS? 提前
有没有什么快速的方法可以使 :visited 链接的颜色与链接本身的颜色相同? 例如: * {color:black} a:link {color:blue} a:visited {color:inh
我读到从 iOS 9 开始,引入了通用链接。请解释深层链接和通用链接之间的区别。我的目标是,一个链接将通过邮件发送给客户。让邮件说有一个项目 A 的报价和一个链接。单击链接时 如果安装了该应用程序,则
因此我们需要对 CSS anchor 伪类使用以下顺序 a:link { color: red } a:visited { color: blue } a:hover { color
我组件的当前路径是http://localhost:3000/dashboard/questionnaire/5bf79ff4c45a150015cef7a9在这个组件里面有 Financials 如
我 rsync 目录“Promotion”包含两台具有不同目录结构的机器之间的绝对符号链接(symbolic link)。因此绝对符号链接(symbolic link)在两台机器上都不起作用。为了使它
我是一名优秀的程序员,十分优秀!