Open bartvde opened 7 years ago
I'm getting the error as well,
Uncaught Error: define cannot be used indirect
at webpackJsonp.219.module.exports (amd-define.js:2)
at Object.<anonymous> (jsonix.js:6103)
at Object.118 (jsonix.js:6129)
at __webpack_require__ (bootstrap f29fa90…:1336)
at fn (bootstrap f29fa90…:754)
at Object.117 (WFS110Context.js:7)
at __webpack_require__ (bootstrap f29fa90…:1336)
at fn (bootstrap f29fa90…:754)
at Object.230 (SMIL_2_0.js:251)
at __webpack_require__ (bootstrap f29fa90…:1336)
I thought webpack was supposed to play nicely with this kind of thing.
@WillieMaddox I made some fixes in a fork https://github.com/boundlessgeo/jsonix/commits/master and published as @boundlessgeo/jsonix
for now, until we get the mainstream version fixed
Let me know if it works for you or not.
Could you please PR a reproducing project? Under jsonix/nodejs/tests/webpack2 analog to browserify.
Sure I will do that @highsource
Actually I wonder if we can get the error reproduced by using the command-line tool, since the error only occurs in the browser with the webpack dev server
yeah command-line it works fine
I can confim that problem still exists for webpack 3.10 and webpack-dev-server 2.11.1.
Hi, I see that this was apparently fixed. I see that there has not been any build in npm. Could you publish it in npm please?
Looks like https://github.com/boundlessgeo/jsonix/commit/3342c011779261a860488b1a692fa09910cd273e was never PRed and/or merged here. So it looks to me like the issue is actually not fixed.
@bartvde, if it works for you, then best PR your fix here?
Right IIRC the issue was that I could not create a test case that failed
Hi, any news or workarounds for this? I'm using webpack 4.x and the error still occurs.
Okay, I could get a workaround for webpack as follows:
Install imports-loader
and exports-loader
and add the following rule to webpack.config.js
:
module : {
rules: [
{
test: require.resolve("jsonix"),
use: ['imports-loader?require=>false', 'exports-loader?Jsonix']
},
]
}
You can then import Jsonix
like so:
import Jsonix from 'jsonix';
The webpack-rule does the following:
jsonix
is loadedjsonix
module it sets require
to false (so jsonix
thinks it runs in the browser)Jsonix
, so that it can be used in ES6 import
statements@highsource the code that checks in which context Jsonix is running should also check for the ES6 import
statement, which is the mostly used way to import modules in webpack. So it would happily run with webpack as well as with native ES6 imports. Thanks for that great library :-)
module : { rules: [ { test: require.resolve("jsonix"), use: ['imports-loader?require=>false', 'exports-loader?Jsonix'] }, ] }
On new versions of imports/exports-loader (I'm using v1.1.0) the equivalent syntax is:
module : {
rules: [
{
test: require.resolve("jsonix"),
use:[
"imports-loader?type=commonjs&additionalCode=var%20require%20=%20null",
"exports-loader?type=commonjs&exports=single|Jsonix"
]
}
]
}
The current define wrapper in JSONIX blocks usage in webpack2, I wonder if it's time to get rid of this?