DanielN DanielN - 3 months ago 61
Node.js Question

How to import PIxi.js in Meteor?

I have a simple app just for testing Meteor and Pixi.js.

My main.jsx (the only script file):

import { Meteor } from 'meteor/meteor';
import React from 'react';
import {render} from 'react-dom';
import PIXI from 'pixi.js';



Meteor.startup(()=>{
render(
<p>zdzdzd</p>,
document.getElementById('container')
);
});


But have an error when importing PIXI

graceful-fs.js:157 Uncaught TypeError: Cannot read property 'prototype' of undefined
patch @ graceful-fs.js:157
meteorInstall.node_modules.graceful-fs.graceful-fs.js @ graceful-fs.js:27
fileEvaluate @ install.js:153
require @ install.js:82
meteorInstall.node_modules.glslify-deps.index.js @ index.js:2
fileEvaluate @ install.js:153
require @ install.js:82
meteorInstall.node_modules.glslify.index.js @ index.js:3
fileEvaluate @ install.js:153
require @ install.js:82
meteorInstall.node_modules.pixi.js.src.core.renderers.webgl.filters.spriteMask.SpriteMaskFilter.js @ SpriteMaskFilter.js:5
fileEvaluate @ install.js:153
require @ install.js:82
meteorInstall.node_modules.pixi.js.src.core.renderers.webgl.managers.MaskManager.js @ MaskManager.js:2
fileEvaluate @ install.js:153
require @ install.js:82
meteorInstall.node_modules.pixi.js.src.core.renderers.webgl.WebGLRenderer.js @ WebGLRenderer.js:2
fileEvaluate @ install.js:153
require @ install.js:82
meteorInstall.node_modules.pixi.js.src.core.sprites.webgl.SpriteRenderer.js @ SpriteRenderer.js:2
fileEvaluate @ install.js:153
require @ install.js:82
meteorInstall.node_modules.pixi.js.src.core.index.js @ index.js:28
fileEvaluate @ install.js:153
require @ install.js:82
meteorInstall.node_modules.pixi.js.src.index.js @ index.js:4
fileEvaluate @ install.js:153
require @ install.js:82
Mp.import @ runtime.js:70
meteorInstall.client.main.jsx @ main.jsx:1
fileEvaluate @ install.js:153
require @ install.js:82
(anonymous function) @ app.js?hash=acf17d5…:42


What is the correct way to import it?

Answer

I'm not sure have you've installed your pixi package, but you should use the main npm pixi package. To use it do the following:

1) Install it: meteor npm install --save pixi

2) Reference it as:

import pixi from 'pixi';
console.log(pixi);

The above will work properly.