0

我升级到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"]
          }]
        }]
      ]
    }
  }
}

babelRelay插件

/* 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);
});
4

1 回答 1

0

您的使用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) {}
于 2016-08-08T06:34:37.107 回答