Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"TypeError: Converting circular structure to JSON" when running babel-node

I have a simple express server that I'm attempting to run on Heroku. Everything works fine locally but when I deploy to Heroku, I get the following error.

/app/node_modules/babel-runtime/node_modules/core-js/library/modules/es6.symbol.js:223
return _stringify.apply($JSON, args);
                       ^

TypeError: Converting circular structure to JSON
     at Object.stringify (native)
     at Object.stringify (/app/node_modules/babel-runtime/node_modules/core-js/library/modules/es6.symbol.js:223:23)
     at stringify (/app/node_modules/babel-runtime/node_modules/core-js/library/fn/json/stringify.js:4:26)
     at compile (/app/node_modules/babel-cli/node_modules/babel-register/lib/node.js:105:42)
     at loader (/app/node_modules/babel-cli/node_modules/babel-register/lib/node.js:144:14)
     at Object.require.extensions.(anonymous function) [as .js] (/app/node_modules/babel-cli/node_modules/babel-register/lib/node.js:154:7)
     at Module.load (module.js:355:32)
     at Function.Module._load (module.js:310:12)
     at Function.Module.runMain (module.js:475:10)
     at Object.<anonymous> (/app/node_modules/babel-cli/lib/_babel-node.js:154:22)

Having a lot of trouble diagnosing this. Here are the dependencies in my package.json.

"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"babel-preset-stage-3": "^6.24.1",
"babel-runtime": "^6.26.0",

And my .babelrc file:

    {
        "presets": ["react", "es2015", "stage-2", "stage-3"],
         "plugins": [
            ["transform-runtime", {
              "polyfill": false,
              "regenerator": true
            }]
          ],
          "ignore": ["node_modules"]
    }
like image 273
Devin Finzer Avatar asked Dec 22 '17 07:12

Devin Finzer


1 Answers

I encountered an exactly same situation, where everything works fine locally but not in production. After some digging I realized that the scripts my production container runs have NODE_ENV=production in them, which only installs dependencies but not devDependencies in my package.json.

Because I specified some of babel plugins/presets in devDependencies, they are only available in local but not in production. That was causing the "Converting circular structure to JSON” error in production.

I moved all dependencies related to babel to dependencies, and the problem was solved.

like image 153
Liz Avatar answered Nov 10 '22 00:11

Liz