在使用webpack和babel-loader为浏览器编译我的应用程序之后,在主函数启动之前就会出现以下错误:
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)
错误的来源是什么以及如何解决?
干杯✨
你必须使用import { curry } from 'ramda'
。你可以看到here rambda如何导出它的模块。它不会导出ramda
模块本身,而是导出各个函数。
如果要访问其他方法,可以使用此方法,例如:
import { curry, addIndex, clone } from 'ramda'
如果您确实希望在一个对象中导出所有值,则可以执行以下操作
import * as R from 'ramda';
const { curry } = R;