ColinEberhardt/json-transforms

FAILED: const jsont = require('json-transforms');

Closed this issue · 9 comments

Without any babel installed, using the REPL (for nodejs 4.5 or 6.5):

> const jsont = require('json-transforms');
/usr/lib/node_modules/json-transforms/index.js:1
(function (exports, require, module, __filename, __dirname) { export { default as identity } from './src/identity';
                                                              ^^^^^^
SyntaxError: Unexpected token export

But I note it comes with a .babelrc file

So I try (the list accumulated over attempts based on various web postings):

sudo npm install --global --save-dev babel-cli babel-preset-es2015 nodemon babel-preset-stage-2 babel-register babel-preset-es2015-rollup babel-plugin-external-helpers rollup-plugin-node-resolve
but I get exactly the same error.

So I try some babel-register:

> require('babel-register')({ only: "json-transforms" });
undefined
> var xjsont = require('json-transforms');

and get the error:

[ReferenceError: babelHelpers is not defined
    at Object.<anonymous> (/usr/lib/node_modules/json-transforms/src/pathRule.js:1:1)
    at Module._compile (module.js:556:32)
    at loader (/usr/lib/node_modules/babel-register/lib/node.js:146:5)
    at Object.require.extensions.(anonymous function) [as .js] (/usr/lib/node_modules/babel-register/lib/node.js:156:7)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/usr/lib/node_modules/json-transforms/index.js:25:17)](url)

So I have to ask, what are you doing to make it work?

After reading:

ES6-style module-loading may not function as expected
Due to technical limitations ES6-style module-loading is not fully supported in a babel-node REPL.

at: http://babeljs.io/docs/usage/cli/

I am trying:

babel-node --presets es2015-node5 --plugins transform-runtime --only json-transforms
> var jsont = require('json-transforms');
module.js:327
    throw err;
    ^
Error: Cannot find module 'babel-runtime/helpers/typeof'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/usr/lib/node_modules/json-transforms/src/identity.js:7:16)
    at Module._compile (module.js:409:26)
    at loader (/usr/lib/node_modules/babel-register/lib/node.js:146:5)
    at Object.require.extensions.(anonymous function) [as .js] (/usr/lib/node_modules/babel-register/lib/node.js:156:7)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)

But my main question is, why is this module using no-transpiled JS2016 code given than nodejs can't use it as it doesn't have a JS2016 engine V8.

Surely it should have been pre-transpiled? (Or npm transpiled on install?)

This seems implied by the fact that I am having to explicitly select json-transforms for transpiling here, it is not being done automatically.

Most likely I am ignorant and have missed something obvious.

Now I try ignoring no modules for transpilation:


$ babel-node --presets es2015-node5 --plugins transform-runtime --ignore false t.js
module.js:327
    throw err;
    ^

Error: Cannot find module 'babel-runtime/core-js/object/keys'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/usr/lib/node_modules/babel-preset-es2015-rollup/node_modules/modify-babel-preset/index.js:1:75)
    at Module._compile (module.js:409:26)
    at loader (/usr/lib/node_modules/babel-register/lib/node.js:146:5)
    at Object.require.extensions.(anonymous function) [as .js] (/usr/lib/node_modules/babel-register/lib/node.js:156:7)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)

I clearly have no idea what I am doing and should leave off

I should note this comment "By default all requires to node_modules will be ignored. You can override this by passing an ignore regex"
at http://stackoverflow.com/questions/33710319/unexpected-reserved-word-import-when-using-babel

Which is why I ask, why does the node module use "exports" (JSPATH seems to as well) if babel is going to ignore it and fail to transpile it?

I'll leave off spamming now for a while, hones!

Hmmm ... looks like a problem with my npm publish step, the package should include the transpiled version of the code, which it doesn't at the moment.

I'll look into this!

thanks

great fix in 1.1.2, thanks.

In your readme example (const rules), nodejs 4.5 rejects closes on 2 lines:

    })
  ),

and gives SyntaxError: missing ) after argument list

but accepts one line

})  ),

e.g.

const xrules = [
  jsont.pathRule(
    '.automobiles{.maker === "Honda"}', d => ({
      Honda: d.runner()
    })  ),
  jsont.pathRule(
    '.{.maker}', d => ({
      model: d.match.model,
      year: d.match.year
    })  ),
  jsont.identity
];

and all works fine! thanks for the fix

Cool - I was just about to point out that 1.1.2 is out and I have verified that this is no longer an issue.

Thanks very much for raising this - much appreciated.

I'll take a quick look at that documentation issue too ...