asciinema / asciinema-player

Web player for terminal session recordings
Apache License 2.0
2.6k stars 259 forks source link

Failed to import `asciinema-player` (missing `"type": "module"`?) #259

Open MiguelGuthridge opened 2 weeks ago

MiguelGuthridge commented 2 weeks ago

Describe the bug

I'm trying to use Asciinema with Svelte. When I try to import * as AsciinemaPlayer from 'asciinema-player';, I get an import error, which Node suggests may be due to an incorrect configuration.

To Reproduce Steps to reproduce the behavior:

  1. npm i -D asciinema-player
  2. import * as AsciinemaPlayer from 'asciinema-player'; within my Svelte project
(node:118652) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
11:18:02 pm [vite] Error when evaluating SSR module /src/components/AsciinemaPlayer.svelte: failed to import "asciinema-player"
|- /home/migue/Source/portfolio/node_modules/asciinema-player/dist/index.js:4719
export { create };
^^^^^^

SyntaxError: Unexpected token 'export'
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1178:20)
    at Module._compile (node:internal/modules/cjs/loader:1220:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

Expected behavior I am able to import and use the Asciinema player.

Versions:

Additional context

Note Node's suggestion to fix the issue:

Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.

I have checked, and your package.json does not have a "type": "module" entry in it, which would explain why the export statement is failing.

MiguelGuthridge commented 2 weeks ago

Opened a PR which will hopefully resolve this. #260