guansss / pixi-live2d-display

A PixiJS plugin to display Live2D models of any kind.
https://guansss.github.io/pixi-live2d-display/
MIT License
870 stars 132 forks source link

Npm export error #14

Closed yeemachine closed 3 years ago

yeemachine commented 3 years ago
SyntaxError: The requested module '../web_modules/pixi-live2d-display.js' does not provide an export named 'Live2DModel'

I'm getting around it right now by just importing the whole thing, but thought I'd bring it up.

import Live2D_Display from 'pixi-live2d-display';
const Live2DModel = Live2D_Display.Live2DModel
guansss commented 3 years ago

The path ../web_modules/pixi-live2d-display.js is strange, as it would typically be node_modules/pixi-live2d-display/lib/index.js. I'm wondering how you used this module, could you provide more information?

yeemachine commented 3 years ago

I'm currently using Rollup/Snowpack to bundle atm. Here's how im importing. which seems to work this way, compared to how pixi gets imported.

import { Application } from '@pixi/app';
import { Ticker, TickerPlugin } from '@pixi/ticker';
import { Renderer } from '@pixi/core';
import { InteractionManager } from '@pixi/interaction';

import Live2D_Display from 'pixi-live2d-display';
const {Live2DModel} = Live2D_Display

which actually still gets me this error

pixi-live2d-display.js:28405 Uncaught (in promise) TypeError: (intermediate value).add(...).load(...).on is not a function
pixi-live2d-display.js:28405 Uncaught (in promise) TypeError: r.on is not a function

Though I did a quick search on the second problem might needing some semicolons?

guansss commented 3 years ago

Alright, I realized that "strange" path was generated by Snowpack.

The first problem seems to be an incompatibility between Snowpack and commonjs modules, there's a related issue with possible solutions. I will consider releasing both the commonjs module and ES module in the future.

And for the second, it's because Pixi has suddenly obsoleted the EventEmitter mixin of PIXI.Loader in v5.3.0, which made the on() method no longer available. The solution is either use a Pixi version lower than 5.3.0, or wait for the next release of this project, which has removed the dependency of PIXI.Loader.

yeemachine commented 3 years ago

Thanks! yup. Updating PIXI to 5.2.4 worked.