Jump to content

using pixi v6 with rollup


luzic
 Share

Recommended Posts

Hi,

I'm getting an error when using pixi.js with rollup. After installing pixi via npm, in the code I do: import * as PIXI from 'pixi.js'

I got the following error:

[!] Error: 'default' is not exported by node_modules/object-assign/index.js, imported by node_modules/@pixi/polyfill/dist/esm/polyfill.js
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
node_modules/@pixi/polyfill/dist/esm/polyfill.js (9:7)
 7:  */
 8: import Polyfill from 'promise-polyfill';
 9: import objectAssign from 'object-assign';
           ^
10:
11: // Support for IE 9 - 11 which does not include Promises
Error: 'default' is not exported by node_modules/object-assign/index.js, imported by node_modules/@pixi/polyfill/dist/esm/polyfill.js
    at error (/Users/leozcliu/Code/Atlas/node_modules/rollup/dist/shared/node-entry.js:5400:30)
    at Module.error (/Users/leozcliu/Code/Atlas/node_modules/rollup/dist/shared/node-entry.js:9824:16)
    at handleMissingExport (/Users/leozcliu/Code/Atlas/node_modules/rollup/dist/shared/node-entry.js:9725:28)
    at Module.traceVariable (/Users/leozcliu/Code/Atlas/node_modules/rollup/dist/shared/node-entry.js:10163:24)
    at ModuleScope.findVariable (/Users/leozcliu/Code/Atlas/node_modules/rollup/dist/shared/node-entry.js:8770:39)
    at BlockScope.findVariable (/Users/leozcliu/Code/Atlas/node_modules/rollup/dist/shared/node-entry.js:3065:38)
    at Identifier$1.bind (/Users/leozcliu/Code/Atlas/node_modules/rollup/dist/shared/node-entry.js:4403:40)
    at AssignmentExpression.bind (/Users/leozcliu/Code/Atlas/node_modules/rollup/dist/shared/node-entry.js:3152:23)
    at ExpressionStatement$1.bind (/Users/leozcliu/Code/Atlas/node_modules/rollup/dist/shared/node-entry.js:3152:23)
    at BlockStatement$1.bind (/Users/leozcliu/Code/Atlas/node_modules/rollup/dist/shared/node-entry.js:3148:31)

 

Here's my rollup.config.js, it must be missing something?

export default [
    {
        input: "src/index.js",
        output: {
            file: "dist/myProject.js",
            name: "myProject",
            format: "umd"
        },
        plugins: [
            resolve()
        ],
        onwarn: function (warning, warn) {
            if (warning.code === 'CIRCULAR_DEPENDENCY') return;
            warn(warning);
        }
    }
];

 

Link to comment
Share on other sites

  • 1 year later...

Rollup.js works well for me with JavaScript.

Debugging command: rollup -cmw
where: -c - create a bundle, -m - debug mode, -w - watch)

Release commands:

  • rollup -c
  • uglifyjs public/js/bundle.js -o public/js/bundle.min.js

rollup.config.js

export default {
    input: "./src/client/main.js",
    output: {
        file: "public/js/bundle.js"
    }
}

src/client/main.js

import * as PIXI from "pixi.js"

const app = new PIXI.Application({
    width: window.innerWidth,
    height: window.innerHeight,
    backgroundColor: 0x2c3e50
});
document.body.appendChild(app.view);

const gr = new PIXI.Graphics();
gr.beginFill(0xffffff);
gr.drawCircle(30, 30, 30);
gr.endFill();
app.stage.addChild(gr);

public/index.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

    <style>
        body {
            margin: 0;
        }
    </style>
</head>

<body>
    <script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>

    <script type="importmap">
        {
            "imports": {
                "pixi.js": "https://cdn.skypack.dev/[email protected]"
            }
        }
    </script>

    <script type="module" src="js/bundle.js"></script>
</body>

</html>

 

Edited by 8Observer8
Link to comment
Share on other sites

But when I try to use Rollup.js and Pixi.js with TypeScript I get the same error:

pixjs-rollup-ts.thumb.png.a1e0e37c848b66140b83541fddef871a.png

rollup.config.js

import babel from "@rollup/plugin-babel";
import resolve from "@rollup/plugin-node-resolve";
import json from "@rollup/plugin-json";
import filesize from "rollup-plugin-filesize";

const extensions = [".ts"];

const babelOptions = {
    babelrc: false,
    extensions,
    exclude: "**/node_modules/**",
    babelHelpers: "bundled",
    presets: [
        [
            "@babel/preset-env",
            {
                loose: true,
                modules: false,
                targets: ">1%, not dead, not ie 11, not op_mini all",
            },
        ],
        "@babel/preset-typescript",
    ],
};

export default {
    input: "./src/main.ts",
    output: { file: "public/js/bundle.js" },
    plugins: [ json(), resolve({ extensions }), babel(babelOptions), filesize() ]
}

src/main.ts

import * as PIXI from "pixi.js"

const app = new PIXI.Application({
    width: window.innerWidth,
    height: window.innerHeight,
    backgroundColor: 0x2c3e50
});
document.body.appendChild(app.view);

const gr = new PIXI.Graphics();
gr.beginFill(0xffffff);
gr.drawCircle(30, 30, 30);
gr.endFill();
app.stage.addChild(gr);

public/index.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script src="js/bundle.js"></script>
</body>

</html>

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...