Closed keroxp closed 5 years ago
Hello,
I had same problem while trying to use EaselJS 2.0 Beta in my react application.
I found a workaround that worked for me: use asynchronous import("@createjs/easeljs")
form, like following:
class App extends Component {
componentDidMount() {
import("@createjs/easeljs")
.then(resp => {
let createjs = resp.createjs;
let {Stage, Shape} = createjs;
let stage = new Stage("myCanvas");
let shape = new Shape();
shape.graphics.beginFill("red").drawRect(0, 0, 120, 120);
stage.addChild(shape);
stage.update();
})
}
render() {
return (
<div className="App">
<canvas id="myCanvas" width="800" height="400"></canvas>
</div>
);
}
}
You can import package at the start of your application and then attach it to the global scope:
window.createjs = resp.createjs;
Of course this is not the best workaround but this is the only one that I found.
The "browser" tag has been dropped from the package files as of beta.4. The "main" tag points to the transpiled commonjs build and is what should be used. The "module" tag points to the source code.
TODO
[x] Is this a question or bug? Stack Overflow is a much better place to ask any questions you may have.
[x] Did you search the issues to see if someone else has already reported your issue? If yes, please add more details if you have any!
[ ] If you're using an older version, have you tried the latest?
[ ] If you're requesting a new feature; provide as many details as you can. Why do you want this feature? Do you have ideas for how this feature should be implemented? Pseudocode is always welcome!
Issue Details
Version used (Ex; 1.0): 2.0.0-beta3
Describe whats happening (Include any relevant console errors, a Gist is preferred for longer errors):
The latest version of easeljs can't correctly bundled installed through npm. I created the smallest example project from 2.0's README
And bundled js with parcel
Bundling finished successfully. But got this error when opening it in browser.
I added codes below:
It seems that an exported object from
@createjs/easeljs
was not compatible with any module system. This is because file bundled by bundler (parcel, browserify...) was not correctly built for module system.Most bundler uses file that set to "browser" field for bundling but
dist/easeljs.min.js
is not compatible with bundler. (for script tag?)I tried to delete
browser
field and let bundler usemodule
, but got:This is the error reported in #972
I tried to delete
module
field, finishing bundle successfully but got:This is the error reported in #987
macOS 10.14, node 10.12, npm 6.4.1
I tried to fix the project but the project itself can't be built (#993) Could you check usage, installation and bundle via npm and modern js bundlers?