Webpack:无法解析'undefined'或'null'的属性`curry`

时间:2017-11-16 15:37:40

标签: javascript node.js webpack babel babel-loader

使用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;
...

所述代码来自依赖ramdabluebird的私有函数库。该库在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

错误的来源是什么以及如何解决?

干杯✨

2 个答案:

答案 0 :(得分:2)

您必须使用import { curry } from 'ramda'。您可以看到here rambda如何导出它的模块。它不会导出ramda模块本身,而是导出各个函数。

如果要访问其他方法,可以使用此方法,例如:

import { curry, addIndex, clone } from 'ramda'

答案 1 :(得分:1)

如果您确实希望在一个对象中导出所有值,则可以执行以下操作

import * as R from 'ramda';
const { curry } = R;
相关问题