Babel-loader: TypeError: Cannot read property 'file' of undefined

Created on 6 Sep 2018  路  6Comments  路  Source: babel/babel-loader

Webpack Version:
^4.17.2

Babel Core Version:
7.0

Babel Loader Version:
^8.0.0-beta.6

Please tell us about your environment:
Windows 7

Current behavior:
I upgraded my babel configuration from ^7.0.0-rc.2 to ^7.0.0, and then the compilation failed.

package.json:

"@babel/core": "^7.0.0",
    "@babel/plugin-proposal-class-properties": "^7.0.0",
    "@babel/plugin-proposal-decorators": "^7.0.0",
    "@babel/plugin-proposal-do-expressions": "^7.0.0",
    "@babel/plugin-proposal-export-default-from": "^7.0.0",
    "@babel/plugin-proposal-export-namespace-from": "^7.0.0",
    "@babel/plugin-proposal-optional-chaining": "^7.0.0",
    "@babel/plugin-proposal-throw-expressions": "^7.0.0",
    "@babel/plugin-syntax-dynamic-import": "^7.0.0",
    "@babel/plugin-syntax-import-meta": "^7.0.0",
    "@babel/plugin-transform-runtime": "^7.0.0",
    "@babel/preset-env": "^7.0.0",
    "@babel/preset-react": "^7.0.0",
    "@babel/preset-typescript": "^7.0.0",
    "@babel/runtime": "^7.0.0",
    "babel-loader": "^8.0.0-beta.6",

.babelrc

{
  "env": {
    "development": {
      "plugins": [
        "dynamic-import-node",
        "react-hot-loader/babel",
        "dva-hmr",
        ["import", { "libraryName": "antd", "style": "css" }]
      ]
    }
  },
  "presets": [
    [
      "@babel/preset-env",
      {
        "modules": false,
        "targets": {
          "browsers": ["IE >= 9"]
        },
        "useBuiltIns": "usage"
      }
    ],
    "@babel/preset-typescript",
    "@babel/preset-react"
  ],
  "plugins": [
    [
      "@babel/transform-runtime",
      {
        "helpers": false
      }
    ],
    ["@babel/plugin-proposal-decorators", { "legacy": true }],
    ["@babel/plugin-proposal-class-properties", { "loose": true }],
    "@babel/proposal-do-expressions",
    "@babel/proposal-export-default-from",
    "@babel/proposal-export-namespace-from",
    "@babel/proposal-optional-chaining",
    "@babel/proposal-throw-expressions",
    "@babel/syntax-dynamic-import",
    "@babel/syntax-import-meta"
  ]
}

output the following:

./src/pages/xshare-managment/router.tsx
Module build failed (from ./node_modules/babel-loader/lib/index.js):
TypeError: Cannot read property 'file' of undefined

I tried set @babel/preset-env to ^7.0.0-rc.2 and compiled successfully!

Expected/desired behavior:

  • What is the expected behavior?
    use @babel/preset-env: ^7.0.0 and compiled successfully!

Most helpful comment

@loganfsmyth sorry, I didn't notice this notice.

I create a reproduction example, I hope it can help you.

All 6 comments

What is the full error stack trace?

@nicolo-ribaudo

Uncaught Error: Module build failed (from ./node_modules/babel-loader/lib/index.js):
TypeError: Cannot read property 'file' of undefined
    at PluginPass.CallExpression (E:\xtpt\xshare-management-platform-plus-front\node_modules\babel-plugin-dva-hmr\lib\index.js:163:33)
    at newFn (E:\xtpt\xshare-management-platform-plus-front\node_modules\@babel\traverse\lib\visitors.js:193:21)
    at NodePath._call (E:\xtpt\xshare-management-platform-plus-front\node_modules\@babel\traverse\lib\path\context.js:53:20)
    at NodePath.call (E:\xtpt\xshare-management-platform-plus-front\node_modules\@babel\traverse\lib\path\context.js:40:17)
    at NodePath.visit (E:\xtpt\xshare-management-platform-plus-front\node_modules\@babel\traverse\lib\path\context.js:88:12)
    at TraversalContext.visitQueue (E:\xtpt\xshare-management-platform-plus-front\node_modules\@babel\traverse\lib\context.js:118:16)
    at TraversalContext.visitSingle (E:\xtpt\xshare-management-platform-plus-front\node_modules\@babel\traverse\lib\context.js:90:19)
    at TraversalContext.visit (E:\xtpt\xshare-management-platform-plus-front\node_modules\@babel\traverse\lib\context.js:146:19)
    at Function.traverse.node (E:\xtpt\xshare-management-platform-plus-front\node_modules\@babel\traverse\lib\index.js:94:17)
    at NodePath.visit (E:\xtpt\xshare-management-platform-plus-front\node_modules\@babel\traverse\lib\path\context.js:95:18)
    at PluginPass.CallExpression (E:\xtpt\xshare-management-platform-plus-front\node_modules\babel-plugin-dva-hmr\lib\index.js:163:33)
    at newFn (E:\xtpt\xshare-management-platform-plus-front\node_modules\@babel\traverse\lib\visitors.js:193:21)
    at NodePath._call (E:\xtpt\xshare-management-platform-plus-front\node_modules\@babel\traverse\lib\path\context.js:53:20)
    at NodePath.call (E:\xtpt\xshare-management-platform-plus-front\node_modules\@babel\traverse\lib\path\context.js:40:17)
    at NodePath.visit (E:\xtpt\xshare-management-platform-plus-front\node_modules\@babel\traverse\lib\path\context.js:88:12)
    at TraversalContext.visitQueue (E:\xtpt\xshare-management-platform-plus-front\node_modules\@babel\traverse\lib\context.js:118:16)
    at TraversalContext.visitSingle (E:\xtpt\xshare-management-platform-plus-front\node_modules\@babel\traverse\lib\context.js:90:19)
    at TraversalContext.visit (E:\xtpt\xshare-management-platform-plus-front\node_modules\@babel\traverse\lib\context.js:146:19)
    at Function.traverse.node (E:\xtpt\xshare-management-platform-plus-front\node_modules\@babel\traverse\lib\index.js:94:17)
    at NodePath.visit (E:\xtpt\xshare-management-platform-plus-front\node_modules\@babel\traverse\lib\path\context.js:95:18)
    at Object../src/pages/xshare-managment/router.tsx (http://localhost:5000/xshare-managment.230fc6bf4771ea510807.async.js:168:7)
    at __webpack_require__ (http://localhost:5000/xshare-managment.html:870:30)
    at fn (http://localhost:5000/xshare-managment.html:238:20)
    at http://localhost:5000/xshare-managment.230fc6bf4771ea510807.async.js:100:16
    at Module.<anonymous> (http://localhost:5000/xshare-managment.230fc6bf4771ea510807.async.js:133:3)
    at Module../src/pages/xshare-managment/index.ts (http://localhost:5000/xshare-managment.230fc6bf4771ea510807.async.js:157:30)
    at __webpack_require__ (http://localhost:5000/xshare-managment.html:870:30)
    at fn (http://localhost:5000/xshare-managment.html:238:20)
    at Object.1 (http://localhost:5000/xshare-managment.230fc6bf4771ea510807.async.js:181:18)
    at __webpack_require__ (http://localhost:5000/xshare-managment.html:870:30)

The dva-hmr plugin doesn't support Babel 7 yet. It is tracked at https://github.com/dvajs/babel-plugin-dva-hmr/issues/14.

I'm moving this issue to https://github.com/babel/babel/issues/8641

@bigbigbo Would you be able to create a reproduction example and add it to the new issue? I'm not able to reproduce the error you've given, so it may depend on the input code that you have. If you can trim down whichever file file is triggering the error, that would be a big help.

@loganfsmyth sorry, I didn't notice this notice.

I create a reproduction example, I hope it can help you.

Was this page helpful?
0 / 5 - 0 ratings