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

CreateJS and Webpack #12

Open
meefox opened this issue Feb 11, 2018 · 5 comments
Open

CreateJS and Webpack #12

meefox opened this issue Feb 11, 2018 · 5 comments

Comments

@meefox
Copy link

meefox commented Feb 11, 2018

CreateJS doesn't work with web pack.
throwing in runtime: createjs.js:58 Uncaught ReferenceError: createjs is not defined

you are try to reference to this.createjs and expecting this to be a window object, but it is actually webpack module wrapper.
could you fix the referencing to exactly CreateJS instance not to this.createjs

Thank you.

@ninique
Copy link

ninique commented Apr 30, 2018

You can use the imports loader and exports loader plugins to deal with this. This is the way I have it configured:

resolve: {
    alias: {
      createjs: 'createjs/builds/1.0.0/createjs.js'
    }
},
module: {
    rules: [
      {
        test: /node_modules[/\\]createjs/,
        loaders: [
          'imports-loader?this=>window',
          'exports-loader?window.createjs'
        ]
      },
  ...
}

Then you can import it normally:

import createjs from 'createjs';

@ismcdonald
Copy link

When using a typescript loader I've additionally had to use

const createjs = require( 'createjs')

instead of import

@jorisnoo
Copy link

jorisnoo commented Jul 7, 2020

Updating the loaders to version 1.1.0, I had to use the following:

rules: [
            {
                test: /node_modules[/\\]createjs/,
                use: [{
                    loader: 'exports-loader',
                    options: {
                        type: 'commonjs',
                        exports: 'single window.createjs',
                    },
                }],
            },
            {
                test: /node_modules[/\\]createjs/,
                use: [{
                    loader: 'imports-loader',
                    options: {
                        wrapper: 'window',
                    },
                }],
            },
        ],

@amalbros
Copy link

amalbros commented Mar 9, 2021

@jorisnoo @ninique I am facing this.getOptions isnot a function after trying your codes.Any solution for the same?

@Aurelain
Copy link

The problem with this.getOptions missing is a versioning problem of imports-loader and exports-loader.
According to the docs, this.getOptions has become available only in webpack 5+.
I was using webpack 4, and I assume so did @amalbros. My solution was to install older versions of loaders:

npm i [email protected] --save-dev
npm i [email protected] --save-dev

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

No branches or pull requests

6 participants