Skip to content

Invalid import paths in JavaScript modules #368

@krutoo

Description

@krutoo

Hi, first of all thanks for great library!

In my case I want to use your library in Node.js. My project is ESM, so when I import Rapier from node_modules it fails with errors like:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/krytoo/Projects/sandbox/node_modules/@dimforge/rapier3d/exports' imported from /Users/krytoo/Projects/sandbox/node_modules/@dimforge/rapier3d/rapier.js

This is because in rapier.js file there is no extensions in import paths:

import * as RAPIER from "./exports"; // here should be extension `.js`
export * from "./exports"; // ...and here
export default RAPIER;
//# sourceMappingURL=rapier.js.map

Also other moment is missing "exports" field in package.json, for example like this:

{
  "name": "@dimforge/rapier3d",
  "...": "...",
  "exports": {
    ".": "./rapier.js"
  }
}

Without exports field it is imposible to import from root of the package, instead I forced to do like this:

// works
import Rapier from '@dimforge/rapier3d/rapier.js';

// not working
import Rapier from '@dimforge/rapier3d';

Package @dimforge/rapier3d works correctly in CommonJS system but that would be really cool to fix import paths and package.json to make it works in ESM projects

If you use TypeScript for building you can use tsc-alias - tiny but great lib to make imports correct after build by tsc

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions