You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am having the same problems as issue #8300 however I did not understand the responses on that thread, I think I will require a more detailed explanation of how to resolve this issue, I couldn't get either of the github links provided as answers to run. I am just getting started with pixi js, but I am familiar with npm. I decided to download pixi.js from npm using npm install pixi.js. When I follow this tutorial: https://pixijs.com/8.x/guides/basics/getting-started everything works as expected as long as the scripts remain within the HTML. As a result my HTML file looks identical to that provided in the tutorial, but I will paste here for clarity:
<!doctype html>
<script src="https://pixijs.download/release/pixi.min.js"></script>
<script type="module">
// Create the application helper and add its render target to the page
const app = new PIXI.Application();
await app.init({ width: 640, height: 360 })
document.body.appendChild(app.canvas);
// Create the sprite and add it to the stage
await PIXI.Assets.load('sample.png');
let sprite = PIXI.Sprite.from('sample.png');
app.stage.addChild(sprite);
// Add a ticker callback to move the sprite back and forth
let elapsed = 0.0;
app.ticker.add((ticker) => {
elapsed += ticker.deltaTime;
sprite.x = 100.0 + Math.cos(elapsed/50.0) * 100.0;
});
</script>
While the sprite doesn't seem to be loading for me, it does create the application and view window and renders essentially a black box with the given dimensions. Playing around with the scripts in the HTML file seems to work, however once I move those scripts to an index.js file and add <script type="module" src="./index.js"> to import that said script, I get "app.js:2 Uncaught ReferenceError: PIXI is not defined" This makes sense because I didn't explicitly import PIXI into my index.js file. So I added the following line to the top of my index.js file:
import * as PIXI from './node_modules/pixi.js';
This gives me a new error: Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
I've played around with this import statement, I've also used: import * as PIXI from 'pixi.js';
with this import statement I am getting: Uncaught TypeError: Failed to resolve module specifier "pixi.js". Relative references must start with either "/", "./", or "../".
I don't understand what's going on at all, usually I can import modules just fine as long as my script tag specifies its type as module. I can't tell if this is an issue with NPM or PIXI itself, but it is not as simple as the tutorials make it seem to actually render your own webpage with pixi enabled. Just getting started has been such a nightmare, I don't understand where I'm going wrong. Can someone please help, and please explain it to me like I'm a total beginner?
All I want is to render a simple application to test this tool out using npm and a basic http server plugin.
Expected Behavior
I should be able to import pixi js in a script that is referenced in the home page's html.
Steps to Reproduce
create a new folder (we will call it "test")
cd into test
run npm init -y
run npm install pixi.js
copy paste the html provided in this tutorial into a file called index.html: https://pixijs.com/8.x/guides/basics/getting-started
cut lines 7-23 out of the html document and move them to a separate file in the same folder called index.js
add this line to the top of index.js: import * as PIXI from 'pixi.js';
remove the empty script tag from index.html
add the following tag in its place: <script type="module" src="./index.js"></script>
serve the web page using npm serve, or http-server, or any simple web server extension for vscode
open the page in google chrome
open the command console and inspect the error
Environment
pixi.js version: latest version
Browser & Version: Version 124.0.6367.119 (Official Build) (arm64)
If you are using Pixi as a NPM package it is best practise to pack all your scripts into one file (using something like Webpack or ESBuild), by using one of these tools you can pack the PIXI code and your code into one file, which is better practise for web.
If you didn't want to do this you can download the .min.js of Pixi from this page (https://github.com/pixijs/pixijs/releases) and include it in your HTML to make PIXI a global object.
As @Jennics-SG said you can included the minifies version of pixi in your html and then reference under the global PIXI object. No need for import * as PIXI from 'pixi.js';
Current Behavior
I am having the same problems as issue #8300 however I did not understand the responses on that thread, I think I will require a more detailed explanation of how to resolve this issue, I couldn't get either of the github links provided as answers to run. I am just getting started with pixi js, but I am familiar with npm. I decided to download pixi.js from npm using
<script src="https://pixijs.download/release/pixi.min.js"></script> <script type="module"> // Create the application helper and add its render target to the page const app = new PIXI.Application(); await app.init({ width: 640, height: 360 }) document.body.appendChild(app.canvas);npm install pixi.js
. When I follow this tutorial: https://pixijs.com/8.x/guides/basics/getting-started everything works as expected as long as the scripts remain within the HTML. As a result my HTML file looks identical to that provided in the tutorial, but I will paste here for clarity:<!doctype html>
While the sprite doesn't seem to be loading for me, it does create the application and view window and renders essentially a black box with the given dimensions. Playing around with the scripts in the HTML file seems to work, however once I move those scripts to an index.js file and add <script type="module" src="./index.js"> to import that said script, I get "app.js:2 Uncaught ReferenceError: PIXI is not defined" This makes sense because I didn't explicitly import PIXI into my index.js file. So I added the following line to the top of my index.js file:
import * as PIXI from './node_modules/pixi.js';
This gives me a new error: Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
I've played around with this import statement, I've also used: import * as PIXI from 'pixi.js';
with this import statement I am getting: Uncaught TypeError: Failed to resolve module specifier "pixi.js". Relative references must start with either "/", "./", or "../".
I don't understand what's going on at all, usually I can import modules just fine as long as my script tag specifies its type as module. I can't tell if this is an issue with NPM or PIXI itself, but it is not as simple as the tutorials make it seem to actually render your own webpage with pixi enabled. Just getting started has been such a nightmare, I don't understand where I'm going wrong. Can someone please help, and please explain it to me like I'm a total beginner?
All I want is to render a simple application to test this tool out using npm and a basic http server plugin.
Expected Behavior
I should be able to import pixi js in a script that is referenced in the home page's html.
Steps to Reproduce
create a new folder (we will call it "test")
cd into test
run npm init -y
run npm install pixi.js
copy paste the html provided in this tutorial into a file called index.html: https://pixijs.com/8.x/guides/basics/getting-started
cut lines 7-23 out of the html document and move them to a separate file in the same folder called index.js
add this line to the top of index.js: import * as PIXI from 'pixi.js';
remove the empty script tag from index.html
add the following tag in its place: <script type="module" src="./index.js"></script>
serve the web page using npm serve, or http-server, or any simple web server extension for vscode
open the page in google chrome
open the command console and inspect the error
Environment
pixi.js
version: latest versionPossible Solution
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: