-
Notifications
You must be signed in to change notification settings - Fork 201
webpack fails at jsonld because of ES6 code in lib/jsonld.js #252
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
Comments
What environment are you running in? I'm pretty sure there's more code that's not ES5. That's partly why the babeled dist/node6/ and webpacked dist/jsonld*.js exist. Can you just use those? The idea is that moving forward we will be using newer ES2015+ features (async/await usage is only a matter of time). If it's just one line that's causing trouble, then propose a patch to consider. See also #251. |
It's not entirely clear to me what node6 refers to and why I'd need to use it with webpack. But webpack is working now that I've switched to this (typescript) code:
|
The dist/node6/ code in the npm distributions is basically just the main code run through babel so that it works with node v6. That dir will go away sometime after v6 end-of-life. |
I just got into the same problem but I cannot change the import as jsonld.js is a transitive dependency in my case. It should definitely be possible to set up babel so that it bundles correctly. But how? |
Ok, I managed to find a workaround setting up babel as follows: I added these yarn add --save-dev
babel-plugin-transform-runtime
babel-core babel-loader
babel-preset-stage-0
babel-preset-env
{
"plugins": [
["transform-runtime", {
"polyfill": false,
"regenerator": true
}]
]
}
|
Got the same issue here. resolve: {
alias: {
jsonld$: path.resolve(root, './node_modules/jsonld/dist/jsonld.min.js')
}
} |
Thank @davidemontanari that solved my issue too. I had webpack working but was experiencing problems in browsers that do not support ES6, now they were tripping up over the spread syntax "...". |
Great @flyon! Glad to help! :) |
@davidemontanari and @flyon thanks for figuring out this patch, but to me this does not feel like a proper solution to the problem. Perhaps exposing the minified version ( Would be happy to test it. |
For anyone experiencing this issue while using CRA, I upgraded from CRA 1.x to 2.x and the issue went away. |
I have just run into the same problem using the karma test framework:
So do I understand correctly that I am using version 1.6.2. The following construct (#251) solves my problem: declare let require: any; // http://stackoverflow.com/questions/34730010/angular2-5-minute-install-bug-require-is-not-defined
const jsonld = require('jsonld/dist/jsonld.js'); However, I would also prefer a clean solution as stated in #251. |
Line 121 it is I just looked at my setup where I also test TS code with karma. Apparently I explicitly include jsonld in {
test: /\.jsx?$/,
loader: 'babel-loader',
include: [
/\/jsonld\//
],
query: {
presets: [ 'env', 'stage-0' ]
},
} |
And I replied the exact same snippet last year 🤦♂. Have you seen it or tried it @tobiasschweizer ? |
jsonld.js source is not ES5. It's using async/await so is ES2017+, I think. The npm package includes code built by webpack and babel. The |
I am used to writing my source files in TypeScript and to distribute them as JavaScript ES5 npm packages (using the tsc transpiler). Wouldn't it be possible to have different distribution packages for jsonld for different environments rather than having different things in one npm package? There would still be only one source to maintain. Would it make sense to add some information to the README about ES versions? I would be happy to create a PR for this. But I would surely need some assistance. |
I think you can't make any assumptions about the ES version of an npm package: https://stackoverflow.com/questions/43393303/which-ecmascript-version-do-the-npm-modules-use I wonder if there could be a thing like differential loading (https://angular.io/guide/deployment#differential-loading) |
I don't use babel, I use tsc. I don't understand how your include helps find the correct version of jsonld. Could you please explain that to me? |
Ah, bummer. I think I dropped
I does not do that. It makes sure that babel compiles jsonld down to ES5. In your case that would be a complete revolution in your case. Maybe you could try adding karma-babel-preprocessor to preprocess the sources of jsonld. |
Ok, now I understand :-)
Good point, thanks. @davidlehn
The source is kept under version control on GitHub, the transpiled code is distributed as an npm package (derived from source). Now it would probably make more sense to choose ES2015 as a target since modern browsers support it. I have also read about the concept of differential loading (#252 (comment)). |
@tobiasschweizer I just switched my project's tests from karma to jest. unless you are herd-pressed on browser testing, I highly recommend this changed. jest is much simpler to configure and the defaults just work The good thing is that you may not need any changes in your test scenarios (I use the A PR says more than a 55 words: hypermedia-app/Alcaeus#123 |
I did not do the setup. But I think we cold give jest a try. Thanks for the hint. |
Closing as a duplicate of #399. |
webpack fails at jsonld because of the use of "..." in jsonld/lib/jsonld.js which is not ES5.
https://github.com/digitalbazaar/jsonld.js/blob/master/lib/jsonld.js#L1040
The text was updated successfully, but these errors were encountered: