Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Babel transformation error: "don't know how to turn this value into a node" #11614

Closed
samstickland opened this issue May 26, 2020 · 22 comments
Closed
Labels
area: downstream i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@samstickland
Copy link

Bug Report

After upgrading webpack and babel I'm now faced with a few errors like this from our vue-jest based test suite, and I have no idea how to go about debugging them:

/home/rof/src/github.com/hubbado/hubbado_core/app/javascript/general-stats/views/GeneralStats/Controls.vue: don't know how to turn this value into a node

Current behavior

This is the only type of stacktrace I get, on around 8 or so tests:

 FAIL  spec/javascript/general-stats/GeneralStats.spec.js
  ● Test suite failed to run

    /Users/samuelstickland/development/hubbado/hubbado_core/app/javascript/general-stats/views/GeneralStats.vue: don't know how to turn this value into a node

      at valueToNode (node_modules/@babel/types/lib/converters/valueToNode.js:87:9)
      at Object.valueToNode (node_modules/@babel/types/lib/converters/valueToNode.js:81:58)
      at Object.exit (node_modules/istanbul-lib-instrument/dist/visitor.js:641:30)
      at PluginPass.exit (node_modules/babel-plugin-istanbul/lib/index.js:158:38)
      at newFn (node_modules/@babel/traverse/lib/visitors.js:179:21)
      at NodePath._call (node_modules/@babel/traverse/lib/path/context.js:55:20)
      at NodePath.call (node_modules/@babel/traverse/lib/path/context.js:42:17)
      at NodePath.visit (node_modules/@babel/traverse/lib/path/context.js:99:8)
      at TraversalContext.visitQueue (node_modules/@babel/traverse/lib/context.js:112:16)
      at TraversalContext.visitSingle (node_modules/@babel/traverse/lib/context.js:84:19)
      at TraversalContext.visit (node_modules/@babel/traverse/lib/context.js:140:19)
      at Function.traverse.node (node_modules/@babel/traverse/lib/index.js:84:17)
      at traverse (node_modules/@babel/traverse/lib/index.js:66:12)
      at transformFile (node_modules/@babel/core/lib/transformation/index.js:107:29)
          at transformFile.next (<anonymous>)
      at run (node_modules/@babel/core/lib/transformation/index.js:35:12)

Input Code

Apologies, I'm not sure what code will be useful to share here.- I'm open to suggestions. Our test suite is currently using vue-jest

Expected behavior
Files continue to be transformed correctly in the test suite

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

  • Filename: babel.config.js
module.exports = function(api) {
  var validEnv = ['development', 'test', 'production']
  var currentEnv = api.env()
  var isDevelopmentEnv = api.env('development')
  var isProductionEnv = api.env('production')
  var isTestEnv = api.env('test')

  if (!validEnv.includes(currentEnv)) {
    throw new Error(
      'Please specify a valid `NODE_ENV` or ' +
        '`BABEL_ENV` environment variables. Valid values are "development", ' +
        '"test", and "production". Instead, received: ' +
        JSON.stringify(currentEnv) +
        '.'
    )
  }

  return {
    presets: [
      isTestEnv && [
        require('@babel/preset-env').default,
        {
          targets: {
            node: 'current'
          }
        }
      ],
      (isProductionEnv || isDevelopmentEnv) && [
        require('@babel/preset-env').default,
        {
          forceAllTransforms: true,
          useBuiltIns: 'entry',
          corejs: 3,
          modules: false,
          exclude: ['transform-typeof-symbol']
        }
      ]
    ].filter(Boolean),
    plugins: [
      require('babel-plugin-macros'),
      require('@babel/plugin-syntax-dynamic-import').default,
      isTestEnv && require('babel-plugin-dynamic-import-node'),
      require('@babel/plugin-transform-destructuring').default,
      [
        require('@babel/plugin-proposal-class-properties').default,
        {
          loose: true
        }
      ],
      [
        require('@babel/plugin-proposal-object-rest-spread').default,
        {
          useBuiltIns: true
        }
      ],
      [
        require('@babel/plugin-transform-runtime').default,
        {
          helpers: false,
          regenerator: true,
          corejs: false
        }
      ],
      [
        require('@babel/plugin-transform-regenerator').default,
        {
          async: false
        }
      ]
    ].filter(Boolean)
  }
}

Environment

npx: installed 1 in 1.922s

  System:
    OS: macOS 10.15.4
  Binaries:
    Node: 14.3.0 - /usr/local/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.4 - /usr/local/bin/npm
  • How you are using Babel: loader (via webpacker)
@babel-bot
Copy link
Collaborator

Hey @samstickland! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

@samstickland
Copy link
Author

Apologies, digging deeper into this and I think it might be an istanbul / jest issue, since removing these lines from jest.config.json makes the issue disappear:

  "collectCoverage": true,
  "collectCoverageFrom": [
    "<rootDir>/app/javascript/**/*.{js,vue}",
    "!<rootDir>/app/javascript/packs/*"
  ]

@nicolo-ribaudo
Copy link
Member

Both of them use Babel under the hood, so lets keep this open.

@Petercopter
Copy link

Same problem here in a vue-jest stack. The error surfaces when trying to upgrade from jest 25.4.0 to 25.5.4 or 26.0.1.

@nicolo-ribaudo
Copy link
Member

Do you have a repository where I can reproduce the issue?

cc @jeysal This might be related to the Babel changes in Jest 25.5.0 (jestjs/jest#9806)

@jeysal
Copy link
Contributor

jeysal commented May 30, 2020

Quite possibly, yeah. Although we don't do a lot of magic there any more, so also quite possible that it's something to be fixed in istanbul. Repro would be good to see what value they try to turn into a node. Also, that error message in valueToNode should definitely print the value 😅

@jeysal
Copy link
Contributor

jeysal commented May 31, 2020

There's also a similar issue on Jest jestjs/jest#10089

@JLHwung
Copy link
Contributor

JLHwung commented Jun 1, 2020

Can you edit your node_modules/istanbul-lib-instrument/dist/visitor.js and add

console.log("coverageDataConstructor: ", coverageData.constructor)

after
https://github.com/istanbuljs/istanbuljs/blob/1b52fe750d1f800c34dbff168614c0c73bd76026/packages/istanbul-lib-instrument/src/visitor.js#L628

Please attach the log after rerunning jest.

The error is thrown because _.isPlainObject(coverageData) returns false, which seems more like an issue of istanbul-lib-instrument.

@samstickland
Copy link
Author

@JLHwung Hi, your change results in the following:

    /Users/samuelstickland/development/hubbado/hubbado_core/app/javascript/general-stats/views/GeneralStats/Controls.vue: don't know how to turn this value into a node

      at valueToNode (node_modules/@babel/types/lib/converters/valueToNode.js:87:9)
      at Object.valueToNode (node_modules/@babel/types/lib/converters/valueToNode.js:81:58)
      at Object.exit (node_modules/istanbul-lib-instrument/dist/visitor.js:642:30)
      at PluginPass.exit (node_modules/babel-plugin-istanbul/lib/index.js:158:38)
      at newFn (node_modules/@babel/traverse/lib/visitors.js:179:21)
      at NodePath._call (node_modules/@babel/traverse/lib/path/context.js:55:20)
      at NodePath.call (node_modules/@babel/traverse/lib/path/context.js:42:17)
      at NodePath.visit (node_modules/@babel/traverse/lib/path/context.js:99:8)
      at TraversalContext.visitQueue (node_modules/@babel/traverse/lib/context.js:112:16)
      at TraversalContext.visitSingle (node_modules/@babel/traverse/lib/context.js:84:19)
      at TraversalContext.visit (node_modules/@babel/traverse/lib/context.js:140:19)
      at Function.traverse.node (node_modules/@babel/traverse/lib/index.js:84:17)
      at traverse (node_modules/@babel/traverse/lib/index.js:66:12)
      at transformFile (node_modules/@babel/core/lib/transformation/index.js:107:29)
          at transformFile.next (<anonymous>)
      at run (node_modules/@babel/core/lib/transformation/index.js:35:12)

coverageDataConstructor:  [Function: Object]

@JLHwung
Copy link
Contributor

JLHwung commented Jun 2, 2020

@samstickland Okay, it seems it is indeed an Object, can you add more debugging output?

const Ctor = coverageData.constructor;
const funcToString = (f) => Function.prototype.toString.call(f);
console.log("instanceof", Ctor instanceof Ctor);
console.log("Ctor", funcToString(Ctor));
console.log("Object", funcToString(Object));

@samstickland
Copy link
Author

@JLHwung Sorry about the delayed reply. Adding that code gets me this:

      at valueToNode (node_modules/@babel/types/lib/converters/valueToNode.js:87:9)
      at Object.valueToNode (node_modules/@babel/types/lib/converters/valueToNode.js:81:58)
      at Object.exit (node_modules/istanbul-lib-instrument/dist/visitor.js:647:30)
      at PluginPass.exit (node_modules/babel-plugin-istanbul/lib/index.js:158:38)
      at newFn (node_modules/@babel/traverse/lib/visitors.js:179:21)
      at NodePath._call (node_modules/@babel/traverse/lib/path/context.js:55:20)
      at NodePath.call (node_modules/@babel/traverse/lib/path/context.js:42:17)
      at NodePath.visit (node_modules/@babel/traverse/lib/path/context.js:99:8)
      at TraversalContext.visitQueue (node_modules/@babel/traverse/lib/context.js:112:16)
      at TraversalContext.visitSingle (node_modules/@babel/traverse/lib/context.js:84:19)
      at TraversalContext.visit (node_modules/@babel/traverse/lib/context.js:140:19)
      at Function.traverse.node (node_modules/@babel/traverse/lib/index.js:84:17)
      at traverse (node_modules/@babel/traverse/lib/index.js:66:12)
      at transformFile (node_modules/@babel/core/lib/transformation/index.js:107:29)
          at transformFile.next (<anonymous>)
      at run (node_modules/@babel/core/lib/transformation/index.js:35:12)

instanceof true
Ctor function Object() { [native code] }
Object function Object() { [native code] }
instanceof true
Ctor function Object() { [native code] }
Object function Object() { [native code] }

@jonathanazulay
Copy link

jonathanazulay commented Jun 15, 2020

@JLHwung

Also getting this when trying to import a stencil project (compiled to es5) into a storybook webcomponents project.

ERR! => Failed to build the preview
ERR! ./packages/x/dist/esm/polyfills/core-js.js
ERR! Module build failed (from ./node_modules/babel-loader/lib/index.js):
ERR! Error: /xx/yy/packages/x/dist/esm/polyfills/core-js.js: don't know how to turn this value into a node
ERR!     at Object.valueToNode (/xx/yy/node_modules/@babel/types/lib/converters/valueToNode.js:87:9)
ERR!     at PluginPass.Expression (/xx/yy/node_modules/babel-plugin-minify-constant-folding/lib/index.js:195:26)
ERR!     at PluginPass.newFn (/xx/yy/node_modules/@babel/traverse/lib/visitors.js:220:17)
ERR!     at newFn (/xx/yy/node_modules/@babel/traverse/lib/visitors.js:179:21)
ERR!     at NodePath._call (/xx/yy/node_modules/@babel/traverse/lib/path/context.js:55:20)
ERR!     at NodePath.call (/xx/yy/node_modules/@babel/traverse/lib/path/context.js:42:17)
ERR!     at NodePath.visit (/xx/yy/node_modules/@babel/traverse/lib/path/context.js:90:31)
ERR!     at TraversalContext.visitQueue (/xx/yy/node_modules/@babel/traverse/lib/context.js:112:16)
ERR!     at TraversalContext.visitSingle (/xx/yy/node_modules/@babel/traverse/lib/context.js:84:19)
ERR!     at TraversalContext.visit (/xx/yy/node_modules/@babel/traverse/lib/context.js:140:19)
ERR!     at Function.traverse.node (/xx/yy/node_modules/@babel/traverse/lib/index.js:84:17)
ERR!     at NodePath.visit (/xx/yy/node_modules/@babel/traverse/lib/path/context.js:97:18)
ERR!     at TraversalContext.visitQueue (/xx/yy/node_modules/@babel/traverse/lib/context.js:112:16)
ERR!     at TraversalContext.visitSingle (/xx/yy/node_modules/@babel/traverse/lib/context.js:84:19)
ERR!     at TraversalContext.visit (/xx/yy/node_modules/@babel/traverse/lib/context.js:140:19)
ERR!     at Function.traverse.node (/xx/yy/node_modules/@babel/traverse/lib/index.js:84:17)

If i add a console.log to the valueToNode function. I get this:

object
object
object
function split() { [native code] }

Here's the core-js.js file shipped with stencil it complains about
https://gist.github.com/jonathanazulay/4d5eaeb6739bf5982a6ac2438f12be47

@JLHwung
Copy link
Contributor

JLHwung commented Jun 15, 2020

@samstickland It seems to me that _.isPlainObject will return true based on the log you posted. It is likely that this function is called multiple times. Can you post the debug output when _.isPlainObject(coverageData) is false? This is why the error is thrown.

@jonathanazulay core-js is a polyfill library, I don't think we should collect coverage data from that, can you ignore dist/esm/polyfills?

If i add a console.log to the valueToNode function. I get this:

I can't follow. What is your console.log statements? Can you post your modified valueToNode source?

@jonathanazulay
Copy link

jonathanazulay commented Jun 15, 2020

@JLHwung

Hm, maybe my issue is a bit different. I'm not collecting coverage data, I'm bundling my application with storybook and get this error. But looking at the stacktrace leads me to babel

My valueToNode looks like this

function valueToNode(value) {
  console.log(value.toString())
  //...restof bodyhere
}

@JLHwung
Copy link
Contributor

JLHwung commented Jun 15, 2020

@jonathanazulay Oh the error is thrown from babel-minify. Currently it is unmaintained, can you remove it and use terser instead?

@JLHwung
Copy link
Contributor

JLHwung commented Aug 12, 2020

@rwaltenberg AFAIK a source map generator should not be passed as a coverage data. Can you share a reproduction repo? This can greatly help debugging issues like plugin integrations.

@rwaltenberg
Copy link

rwaltenberg commented Aug 12, 2020

@JLHwung I'm having a problem with an identical stack trace.

@samstickland It seems to me that _.isPlainObject will return true based on the log you posted. It is likely that this function is called multiple times. Can you post the debug output when _.isPlainObject(coverageData) is false? This is why the error is thrown.

I have changed /node_modules/@babel/types/lib/converters/valueToNode.js#L87-L87 to

throw new Error(value.constructor.name);

and got SourceMapGenerator as a result.

@rwaltenberg
Copy link

@rwaltenberg AFAIK a source map generator should not be passed as a coverage data. Can you share a reproduction repo? This can greatly help debugging issues like plugin integrations.

I'll try to create a public repo with the reproduction. In the meanwhile by adding

try {
    value = JSON.parse(value);
  } catch {}

just before that isPlainObject test seems to have solved the issue

@rwaltenberg
Copy link

@JLHwung here it is: https://github.com/rwaltenberg/jest-coverage-error

npx jest will run. npx jest --coverage will fail

@JLHwung
Copy link
Contributor

JLHwung commented Aug 12, 2020

@rwaltenberg Thanks for the reproduction repo! I believe it is a bug in istanbul-lib-instrument and I have filed a fix in istanbuljs/istanbuljs#576.

@samstickland
Copy link
Author

This is now fixed in vue-jest@4.0.0-rc.0. Please see jestjs/jest#10089 (comment)

@JLHwung
Copy link
Contributor

JLHwung commented Sep 15, 2020

Closing this as the downstream issue is fixed.

@JLHwung JLHwung closed this as completed Sep 15, 2020
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Dec 16, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: downstream i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

8 participants