Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No ES module support #237

Open
ajmeese7 opened this issue Feb 1, 2023 · 6 comments
Open

No ES module support #237

ajmeese7 opened this issue Feb 1, 2023 · 6 comments

Comments

@ajmeese7
Copy link

ajmeese7 commented Feb 1, 2023

svelte-routing doesn't appear to be written in CJS, but also doesn't appear to be a valid ES module (i.e. it doesn't have "type": "module" or an .mjs extension for the entry point). Please contact the package author to fix.

Any chance you're willing to push an update for this?

@EmilTholin
Copy link
Owner

EmilTholin commented Feb 2, 2023

Hi @ajmeese7!

This sounds like a reasonable addition. To my understanding adding "type": "module" to package.json would be a breaking change, so the alternative non-breaking way forward is to rename the entry file index.js to index.mjs.

{
  "name": "svelte-routing",
  "version": "1.6.0",
  "description": "A declarative Svelte routing library with SSR support",
- "main": "src/index.js",
+ "main": "src/index.mjs",

Does that sound right to you?

@ajmeese7
Copy link
Author

ajmeese7 commented Feb 2, 2023

Hey @EmilTholin! That sounds like it should work in theory, I can try it locally by modifying my node_modules package and see if the message goes away if you'd like.

@atsepkov
Copy link

I'm running into this too, the .mjs approach didn't work for me, giving me the following error:

[webpack-watch]     Module build failed: Error: ENOENT: no such file or directory, open '/Users/alex/work/personal/svelte-ssr-webpack-example/node_modules/svelte-routing/src/index.js'
[webpack-watch]      @ ./components/pages/Home.svelte 25:0-47 99:14-20
[webpack-watch]      @ ./client-entry-scripts/Home.js
[2] [nodemon] restarting due to changes...
[2] [nodemon] starting `node dist/bundle.js`
[2] node:internal/modules/cjs/loader:1094
[2]     throw new ERR_REQUIRE_ESM(filename, true);
[2]     ^
[2]
[2] Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/alex/work/personal/svelte-ssr-webpack-example/node_modules/svelte-routing/src/index.mjs not supported.
[2] Instead change the require of /Users/alex/work/personal/svelte-ssr-webpack-example/node_modules/svelte-routing/src/index.mjs to a dynamic import() which is available in all CommonJS modules.

Which I don't understand, since there is no sign of original index.js file in the repo anymore since it's been renamed, nor do I see any require statements in the code that should be changed. The import in my own module uses ESM syntax as well: import { Router, Route } from 'svelte-routing'

occidens added a commit to diagraphics/svelte-routing that referenced this issue Aug 7, 2023
@krishnaTORQUE
Copy link
Collaborator

This has been fixed in the latest version. (MAYBE)
Please confirm so that I can close this issue.

@timotheus90
Copy link

timotheus90 commented Jul 9, 2024

I'm having issue importing the project from node modules, while running jest tests with --experimental-vm-modules:

    import { jwtVerify } from 'jose'
    // only works like this (relative import):
    import { navigate } from '@/../node_modules/svelte-routing'

Whats the difference between jose and svelte-routing:

turns out jose specifies those exports

  "exports": {
    ".": {
      "import": "./dist/node/esm/index.js",
      "require": "./dist/node/cjs/index.js"
    },

Maybe you can add those in your package.json as well:

  "exports": {
    ".": {
      "import": "./src/index.js",
      "require": "./src/index.js",
      "types": "./types/index.d.ts",
      "svelte": "./src/index.js"
    }
  },

(this fixes the issue with jest esm imports)

@webJose
Copy link

webJose commented Jul 9, 2024

Maybe this helps: https://publint.dev/svelte-routing@2.13.0

Also: https://arethetypeswrong.github.io/?p=svelte-routing%402.13.0

This last one looks weird: It has a check next to "node 16 (from ESM)" but next to the check has (CJS). May be an indication of something not quite right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants