简体   繁体   English

导入的依赖项需要另一个依赖项首先在 scope 中可用

[英]Imported dependency requires another dependency to be first available in scope

I'm trying to import a library that extends another one , here's my first approach:我正在尝试导入一个扩展另一个库的库,这是我的第一种方法:

import * as PIXI from 'pixi.js';
import 'pixi-layers'; // extends PIXI classes

I get an Uncaught ReferenceError: PIXI is not defined on runtime when pixi-layers tries to Object.assign on a PIXI class.pixi-layers尝试在Object.assign上分配 Object.assign 时,我得到一个未捕获的Uncaught ReferenceError: PIXI is not defined on runtime。

I suppose this is related to how webpack's hoisting, I've tried to use:我想这与我尝试使用的 webpack 的提升方式有关:

module.exports = {
    // ...
    plugins: [
        new webpack.ProvidePlugin({
            PIXI: 'pixi.js',
        }),
    ],
};

PIXI remains unavailable to pixi-layers , how can I bundle pixi-layers and make sure it can actually work with the PIXI object? PIXI 对pixi-layers仍然不可用,我如何捆绑pixi-layers并确保它实际上可以与 PIXI object 一起使用?

Turns out providing PIXI as a plugin through the webpack config file was the solution, I just has this same config file compile in the wrong location (paths are hard).结果证明通过 webpack 配置文件将 PIXI 作为插件提供解决方案,我只是在错误的位置编译了相同的配置文件(路径很难)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在具有“循环”依赖性的文件的顶级范围中访问导入的模块? - Access imported module in top level scope of file with 'circular' dependency? qbo3 依赖需要 AND 和 OR - qbo3 Dependency requires AND and OR Bower依赖性更新可用 - Bower dependency updates available 使用Angular $ scope依赖与不依赖之间的区别 - Difference between using Angular $scope dependency and no dependency 捆绑为 UMD 的 React 组件在通过另一个 React 应用程序中的脚本标签导入时无法加载依赖项 - React component bundled as an UMD can't load a dependency when imported via script tag in another react app 我可以将一个方法添加到另一个模块中用作依赖项的requirejs模块,并在每次将模块作为依赖项加载时使用它吗? - Can I add a method to a requirejs module used as dependency in another module and have it available every time the module is loaded as dependency? 为什么使用另一个依赖项的依赖项是不好的做法? - Why is using a dependency of another dependency a bad practice? NestJS 无法解析导入模块的依赖 - NestJS can't resolve dependency of imported module 笑话如何模拟依赖项所需要的模块? - How does jest mock the module a dependency requires? 在依赖于 $filter 的 AngularJs 控制器中测试 $scope - Testing $scope in AngularJs controller with dependency on $filter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM