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

ES2015 modules does not supported by current node.js, but present in dist #13

Closed
Delagen opened this issue Mar 20, 2017 · 15 comments
Closed

Comments

@Delagen
Copy link

Delagen commented Mar 20, 2017

node.js: 7.7.3

dist unsupported code

import path from 'path';
import loaderUtils from 'loader-utils';

...

export default valLoader;
C:\12341234>npm i val-loader
C:\12341234
`-- val-loader@1.0.0
  `-- loader-utils@1.1.0
    +-- big.js@3.1.3
    +-- emojis-list@2.1.0
    `-- json5@0.5.1

npm WARN enoent ENOENT: no such file or directory, open 'C:\12341234\package.json'
npm WARN 12341234 No description
npm WARN 12341234 No repository field.
npm WARN 12341234 No README data
npm WARN 12341234 No license field.

C:\12341234>node
> require("val-loader")
C:\12341234\node_modules\val-loader\dist\index.js:1
(function (exports, require, module, __filename, __dirname) { import path from 'path';
                                                              ^^^^^^
SyntaxError: Unexpected token import


C:\12341234>node -v
v7.7.3

@michael-ciniawsky
Copy link
Member

@Delagen Does it work with webpack ?

@michael-ciniawsky
Copy link
Member

The main field in package.json looks wrong, should be dist/cjs.js instead of dist/index.js https://github.com/webpack-contrib/val-loader/blob/master/package.json#L6

cc @jhnns @d3viant0ne @bebraw

@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Mar 20, 2017

@Delagen Could you try by manually changing to "main": "dist/cjs.js" ?

@bebraw
Copy link

bebraw commented Mar 20, 2017

@michael-ciniawsky That also expects src/cjs.js to work like here.

@Delagen
Copy link
Author

Delagen commented Mar 20, 2017

@michael-ciniawsky no this file in npm package
And it does not work with webpack with the same message.
Currently i simply replaced with

var path = require('path');
var loaderUtils = require('loader-utils');

...

module.exports.default = valLoader;

@michael-ciniawsky
Copy link
Member

@bebraw Yep I thought maybe just the reference in package.json was wrong. Needs to be fixed in anycase 😛 . Was a webpack-defaults version used, before the CJS Proxy landed, or is that a bug in webpack-defaults?

@bebraw
Copy link

bebraw commented Mar 20, 2017

@michael-ciniawsky Current webpack-defaults is correct but the cjs.js tweak didn't make it into the PR for some reason.

@jhnns
Copy link
Member

jhnns commented Mar 20, 2017

Maybe I did something wrong 😁 good catch 👍

@jhnns jhnns closed this as completed in #14 Mar 20, 2017
@joshwiens
Copy link
Member

@jhnns - The pull request to add the commonjs proxy hadn't been merged with you upgraded this.

@Delagen
Copy link
Author

Delagen commented Mar 21, 2017

@jhnns @bebraw @michael-ciniawsky
Seems to not fixed

@bebraw bebraw reopened this Mar 21, 2017
@Delagen
Copy link
Author

Delagen commented Mar 21, 2017

Module build failed: C:\projects\...\node_modules\val-loader\dist\index.js:1
(function (exports, require, module, __filename, __dirname) { import path from 'path';
                                                              ^^^^^^
SyntaxError: Unexpected token import

Again: Node.js does not support ES2015 modules without additional flags

@bebraw
Copy link

bebraw commented Mar 21, 2017

Yeah, it doesn't transform modules because of "modules": false, at Babel configuration.

@Delagen
Copy link
Author

Delagen commented Mar 21, 2017

I think Template String also not supported in Node.JS 4

@bebraw
Copy link

bebraw commented Mar 21, 2017

babel-preset-env figures out which features to compile based on the version definition. Looks like it's set to 4.3 minimum at the moment.

@Delagen
Copy link
Author

Delagen commented Mar 21, 2017

OK. https://kangax.github.io/compat-table/es6/ template literals supported by Node.js 4
So modules must be set to commonjs
More it's default.

modules
"amd" | "umd" | "systemjs" | "commonjs" | false, defaults to "commonjs".

Enable transformation of ES6 module syntax to another module type.

Setting this to false will not transform modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants