Code Monkey home page Code Monkey logo

Comments (3)

steel97 avatar steel97 commented on June 2, 2024 1

@noonian can you please check if issue gone with this branch: https://github.com/steel97/pixi-tilemap/tree/cjs-test
I removed "type": "module" from package.json
you can install this version by changing your package.json:
"@pixi/tilemap": "github:steel97/pixi-tilemap#cjs-test"

from tilemap.

ivanpopelyshev avatar ivanpopelyshev commented on June 2, 2024

Can you please check, i just published version for v7?

from tilemap.

noonian avatar noonian commented on June 2, 2024

FYI: I am also unable to import @pixi/tilemap in my Pixi v7 application.

Unfortunately I don't have useful logs and I'm using Pixi via ClojureScript so my tooling configuration is unlikely to help in diagnosing the issue.

Update:

I've tracked the issue to differences between node module types. I think the core issue is that @pixi/tilemap has "type": "module" in package.json and other @pixi packages I am using do not.

It appears @pixi/tilemap works if you import it from a node project that uses "type": "module in package.json, but using require("@pixi/tilemap") (commonjs) fails.

const { Tilemap } = require("@pixi/tilemap");
console.log("foo", Tilemap);

Results in an error:

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/noonian/projects/pixi-tilemap-repro/node_modules/@pixi/tilemap/dist/pixi-tilemap.umd.js from /Users/noonian/projects/pixi-tilemap-repro/index.js not supported.
pixi-tilemap.umd.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename pixi-tilemap.umd.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /Users/noonian/projects/pixi-tilemap-repro/node_modules/@pixi/tilemap/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

The tooling I am using from ClojureScript (shadow-cljs) "guesses" which way to import the library based on the keys "module", "browser", and "main" in package.json, none of which are present in @pixi/tilemap. So I can work around this issue by hacking the package.json in my node_modules before compilation and adding "main": "./dist/pixi-tilemap.js" or "module": "./dist/pixi-tilemap.es.js", to my node_modules/@pixi/tilemap/package.json after installing my dependencies.

I could not get my repro script to run using commonjs requires without removing "type": "module" from the package.json in my local node_modules. I have not tried getting this working using a bundler like webpack.

from tilemap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.