Skip to content

Instantly share code, notes, and snippets.

@JacobFischer
Last active March 14, 2020 01:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JacobFischer/ed8dd2dd2139cc830efd0ebcb4ac145a to your computer and use it in GitHub Desktop.
Save JacobFischer/ed8dd2dd2139cc830efd0ebcb4ac145a to your computer and use it in GitHub Desktop.
pixi.js TypeScript global error
dist/
node_modules/
package-lock.json

pixi.js TypeScript global error

To demo the bug in pixijs/pixijs#6445

How to

  1. clone this gist git clone git@github.com:JacobFischer/pixi-ts-global-error.git
  2. npm install
  3. npm run build
  4. This should create a dist/ directory, load up dist/index.html in a browser
  5. see the following error in the console:
Uncaught ReferenceError: PIXI is not defined
    at eval (index.ts:5)
    at Object../index.ts (index_bundle.js:96)
    at __webpack_require__ (index_bundle.js:20)
    at index_bundle.js:84
    at index_bundle.js:87
import { utils } from "pixi.js";
// This will work
utils.skipHello();
console.log("About to use 'PIXI' which is not globally defined");
// Because we imported the "pixi.js" package, there is a side-effect where
// all the pixi.js types polluted the global namespace, however none
// actually exist globally at run time.
// So, this line will blow up.
const sprite = new PIXI.Sprite();
console.log("I will never run!", sprite);
The MIT License (MIT)
Copyright (c) 2020 Jacob Fischer
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
{
"name": "pixi-ts-global-error",
"version": "1.0.0",
"description": "reproduce pixi.js ts global error",
"main": "dist/index.js",
"repository": {
"type": "git",
"url": "https://github.com/ed8dd2dd2139cc830efd0ebcb4ac145a.git"
},
"author": "Jacob Fischer",
"license": "MIT",
"dependencies": {
"@types/html-webpack-plugin": "3.2.2",
"@types/webpack": "4.41.7",
"html-webpack-plugin": "3.2.0",
"pixi.js": "5.2.1",
"ts-loader": "6.2.1",
"ts-node": "8.6.2",
"typescript": "3.8.3",
"webpack": "4.42.0",
"webpack-cli": "3.3.11"
},
"scripts": {
"build": "webpack",
"clean": "rm -rf dist"
}
}
{
"compilerOptions": {
"module": "commonjs",
"strict": true,
"esModuleInterop": true
}
}
import HtmlWebpackPlugin from "html-webpack-plugin";
import { resolve } from "path";
import { Configuration } from "webpack";
module.exports = {
entry: resolve(__dirname, 'index.ts'),
mode: "development",
output: {
path: resolve(__dirname, './dist'),
},
plugins: [
new HtmlWebpackPlugin() ,
],
} as Configuration;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment