【发布时间】:2018-04-30 05:25:41
【问题描述】:
使用浏览器的 webpack 和 babel-loader 编译我的应用程序后,在 main 函数启动之前立即出现以下错误:
Uncaught TypeError: Cannot destructure property `curry` of 'undefined' or 'null'.
at Object../node_modules/@qzdio/f/lib/combinators/sync.js (index-c1596672f4.js:formatted:268)
at n (runtime-74c3f0da77.js:formatted:10)
at Object../node_modules/@qzdio/f/lib/combinators/index.js (index-c1596672f4.js:formatted:251)
at n (runtime-74c3f0da77.js:formatted:10)
at Object../node_modules/@qzdio/f/lib/index.js (index-c1596672f4.js:formatted:723)
at n (runtime-74c3f0da77.js:formatted:10)
at Object../dist/graph/visualizer/src/index.js (index-c1596672f4.js:formatted:9)
at n (runtime-74c3f0da77.js:formatted:10)
at window.webpackJsonp (runtime-74c3f0da77.js:formatted:26)
at index-c1596672f4.js:formatted:1
错误代码是以下内容的 ES5 转译:
import R from 'ramda';
const { curry } = R;
// I :: a -> a
const I = (x) => x;
...
上述代码来自依赖ramda 和bluebird 的私有函数库。该库在 Node.js 8.9.1 下使用和运行。
使用的 webpack config 直接来自 philipwalton 的 webpack-esnext-boilerplate(非常适合从 :D 开始)
版本:
- babel-cli: ^6.26.0,
- babel-loader: ^7.1.2,
- webpack:^3.8.1,
- 浏览器:Google Chrome 版本 62.0.3202.89(官方版本)(64 位),
- Node.js:8.9.1,
- npm: 5.5.1
错误的根源是什么,如何解决?
干杯✨
【问题讨论】:
-
这
const R = require('ramda');有效吗? -
你试过
import { curry } from 'ramda' -
它们都是行的有效排列是,但为了在 webpack 中测试它们,我必须提交到库,然后在 npm 上推送一个补丁版本。但是,我可以向您保证两者都在节点环境中工作,因为我在库的其他文件中有这些确切的行,并且如前所述,库在节点中正确加载。我的猜测是,从 webpack 的角度来看,这更像是一个配置/转换问题。但如果你坚持我会做出改变
-
更新到
import R from 'ramda';然后使用R.curry解决同样的错误;import { curry } from 'ramda'似乎可以解决问题。 @dzm 知道为什么吗?
标签: javascript node.js webpack babeljs babel-loader