Babel - 类型错误:在"foreign"中指定的插件 1 在调用时应该返回一个对象,但返回"布尔值"



我升级到babel-core 6.13.2现在我得到这个错误。

/var/www/html/kalahi-rf/node_modules/babel-core/lib/transformation/file/options/option-manager.js:120
  throw new TypeError(messages.get("pluginNotObject", loc, i, typeof obj === "undefined" ? "undefined" : (0, _typeof3.default)(obj)) + loc + i);
  ^
TypeError: Plugin 1 specified in "foreign" was expected to return an object when invoked but returned "boolean"foreign1
at Function.memoisePluginContainer (/var/www/html/kalahi-rf/node_modules/babel-core/lib/transformation/file/options/option-manager.js:120:13)
at Function.normalisePlugin (/var/www/html/kalahi-rf/node_modules/babel-core/lib/transformation/file/options/option-manager.js:141:32)
at /var/www/html/kalahi-rf/node_modules/babel-core/lib/transformation/file/options/option-manager.js:181:30
at Array.map (native)
at Function.normalisePlugins (/var/www/html/kalahi-rf/node_modules/babel-core/lib/transformation/file/options/option-manager.js:153:20)
at OptionManager.mergeOptions (/var/www/html/kalahi-rf/node_modules/babel-core/lib/transformation/file/options/option-manager.js:245:36)
at /var/www/html/kalahi-rf/node_modules/babel-core/lib/transformation/file/options/option-manager.js:254:17
at /var/www/html/kalahi-rf/node_modules/babel-core/lib/transformation/file/options/option-manager.js:342:20
at Array.map (native)
at OptionManager.resolvePresets (/var/www/html/kalahi-rf/node_modules/babel-core/lib/transformation/file/options/option-manager.js:305:20)
at OptionManager.mergeOptions (/var/www/html/kalahi-rf/node_modules/babel-core/lib/transformation/file/options/option-manager.js:253:29)
at OptionManager.init (/var/www/html/kalahi-rf/node_modules/babel-core/lib/transformation/file/options/option-manager.js:383:12)
at compile (/var/www/html/kalahi-rf/node_modules/babel-register/lib/node.js:103:45)
at loader (/var/www/html/kalahi-rf/node_modules/babel-register/lib/node.js:148:14)
at Object.require.extensions.(anonymous function) [as .js] (/var/www/html/kalahi-rf/node_modules/babel-register/lib/node.js:158:7)
at Module.load (module.js:458:32)

有人遇到这个错误吗?谢谢。

.babelrc

{
  "plugins": ["./server/utils/babelRelayPlugin"],
  "presets": ["react", "es2015", "stage-0"],
  "env": {
    "development": {
      "plugins": [
        ["react-transform", {
          "transforms": [{
            "transform": "react-transform-hmr",
            "imports": ["react"],
            "locals": ["module"]
          }, {
            "transform": "react-transform-catch-errors",
            "imports": ["react", "redbox-react"]
          }]
        }]
      ]
    }
  }
}

babelRelayPlugin

/* eslint-disable no-var, func-names, prefer-arrow-callback, global-require */
var fs = require('fs');
var path = require('path');
var jsonFile = path.join(__dirname, '../data/schema.json');
// Read the schema.json file only if it exists, this fixed
// the problem of using babelRelayPlugin, defined in .babelrc,
// and running npm run update when the file doesn't exist
fs.access(jsonFile, fs.F_OK, function (err) {
  if (!err) module.exports = require('babel-relay-plugin')(require(jsonFile).data);
});

您使用fs.access意味着您的module.exports =行可以在 Babel已经运行并完成处理插件之后运行。你应该

module.exports = require('babel-relay-plugin')(require(jsonFile).data);

因为不清楚你想做什么。你目前对错误什么都不做的方法只是意味着在没有初始化插件的情况下,Babel有可能会运行。

如果您绝对需要fs.access检查,请同步执行:

// Read the schema.json file only if it exists, this fixed
// the problem of using babelRelayPlugin, defined in .babelrc,
// and running npm run update when the file doesn't exist
try {
  fs.accessSync(jsonFile, fs.F_OK);
  module.exports = require('babel-relay-plugin')(require(jsonFile).data);
} catch(e) {}

最新更新