Skip to content

incompatible with native javascript modules #348

@trusktr

Description

@trusktr

It'd be nice to update import statements so that the lib is easy to import with native ES Modules.

At the moment, this does not work:

<script type="importmap">
	{
		"imports": {
			"@dimforge/rapier3d": "https://cdn.jsdelivr.net/npm/@dimforge/rapier3d@0.19.0/rapier.js"
		}
	}
</script>

<script type="module">
	import * as RAPIER from '@dimforge/rapier3d'
</script>

This will fail with

GET https://cdn.jsdelivr.net/npm/@dimforge/rapier3d@0.19.0/exports net::ERR_ABORTED 404 (Not Found)

This is because https://cdn.jsdelivr.net/npm/@dimforge/rapier3d@0.19.0/exports does not exist. The file https://cdn.jsdelivr.net/npm/@dimforge/rapier3d@0.19.0/exports.js does exist, but appending .js to URLs is not part of native ES Module behavior. A URL to JavaScript can be anything, and only the MIME type determines if it will be executed as JavaScript.

Solving this problem has a potentially easy solution: adding .js to all import statements.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions