Babel很难编译它应该忽略的插件

时间:2016-07-13 03:36:40

标签: reactjs webpack babel

尝试使用webpack加载器编译我的代码,我已将其设置为忽略node_modules并且无法绕过下面的错误。我已经尝试清除我的node_modules并重新安装以及添加和删除软件包但是无法清除该块:

    /home/mgarf/Documents/testApp/node_modules/babel-plugin-     transform-react-jsx/lib/index.js:16
    var visitor = require("babel-helper-builder-react-jsx")({ /*istanbul ignore next*/
                                                         ^

    TypeError: require(...) is not a function
    at exports.default (index.js:14:17)
    at Function.memoisePluginContainer (/home/mgarf/Documents/testApp/node_modules/babel-core/lib/transformation/file/options/option-manager.js:134:13)
    at Function.normalisePlugin (/home/mgarf/Documents/testApp/node_modules/babel-core/lib/transformation/file/options/option-manager.js:168:32)
    at /home/mgarf/Documents/testApp/node_modules/babel-core/lib/transformation/file/options/option-manager.js:208:30
    at Array.map (native)
    at Function.normalisePlugins (/home/mgarf/Documents/testApp/node_modules/babel-core/lib/transformation/file/options/option-manager.js:180:20)
    at OptionManager.mergeOptions (/home/mgarf/Documents/testApp/node_modules/babel-core/lib/transformation/file/options/option-manager.js:300:36)
    at /home/mgarf/Documents/testApp/node_modules/babel-core/lib/transformation/file/options/option-manager.js:371:14
    at /home/mgarf/Documents/testApp/node_modules/babel-core/lib/transformation/file/options/option-manager.js:392:24
    at Array.map (native)

这是我的webpackconfig片段。

var webpack = require('webpack');
require('style-loader');
require('css-loader');
require('babel-register')({
   ignore: /\.css$/,
});

...

module: {
      loaders: [
        {
          test: /\.js$/,
          exclude: /node_modules/,
          loader: 'babel-loader',
          query: {
            plugins: [
              ['react-transform', {
                transforms: [
                  {
                    transform: 'react-transform-hmr',
                    imports: ['react'],
                    locals: ['module']
                  }, {
                    transform: 'react-transform-catch-errors',
                    imports: ['react', 'redbox-react']
                  }
                ]
              }]
            ]
          }
        },
        { test: /\.css$/, exclude: /node_modules/, loader: "style-loader!css-loader" }
      ]
    }

和package.json:

      "dependencies": {
        "async": "^1.5.2",
        "bcrypt-nodejs": "^0.0.3",
        "body-parser": "^1.15.1",
        "bookshelf": "^0.10.0",
        "compression": "^1.6.2",
        "cookie-parser": "^1.4.1",
        "dotenv": "^2.0.0",
        "express": "^4.13.4",
        "express-validator": "^2.20.4",
        "jsonwebtoken": "^5.7.0",
        "knex": "^0.11.7",
        "moment": "^2.12.0",
        "morgan": "^1.7.0",
        "mysql": "^2.10.2",
        "nodemailer": "^2.3.0",
        "nunjucks": "^2.4.1",
        "react": "^15.2.1",
        "react-cookie": "^0.4.5",
        "react-dom": "^15.2.1",
        "react-redux": "^4.4.5",
        "react-router": "^2.4.0",
        "react-transform-catch-errors": "^1.0.2",
        "react-transform-hmr": "^1.0.4",
        "redbox-react": "^1.2.4",
        "redux": "^3.3.1",
        "redux-thunk": "^2.0.1",
        "request": "^2.69.0",
        "webpack": "^1.12.14",
        "webpack-dev-middleware": "^1.6.1",
        "webpack-hot-middleware": "^2.10.0",
        "whatwg-fetch": "^0.11.0"
      },
      "devDependencies": {
        "babel-core": "^6.7.2",
        "babel-loader": "^6.2.4",
        "babel-plugin-react-transform": "^2.0.2",
        "babel-polyfill": "^6.7.2",
        "babel-preset-es2015": "^6.6.0",
        "babel-preset-react": "^6.5.0",
        "babel-plugin-react-transform": "^2.0.0-beta1",
        "babel-plugin-rewire": "^1.0.0-rc-3",
        "babel-plugin-transform-export-extensions": "^6.8.0",
        "babel-register": "^6.8.0",
        "chai": "^3.5.0",
        "css-loader": "^0.23.1",
        "enzyme": "^2.3.0",
        "fetch-mock": "3.0.2",
        "mocha": "^2.4.5",
        "react-addons-test-utils": "^15.0.2",
        "react-date-picker": "^5.3.21",
        "redux-mock-store": "^1.0.2",
        "sinon": "^1.17.3",
        "sinon-chai": "^2.8.0",
        "style-loader": "^0.13.1",
        "supertest": "^1.2.0"
      },
      "engines": {
        "node": "6.1.0"
      }
    }

0 个答案:

没有答案