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

Cannot use in typescript + vite environnement #441

Open
xlaussel opened this issue Jun 7, 2022 · 2 comments
Open

Cannot use in typescript + vite environnement #441

xlaussel opened this issue Jun 7, 2022 · 2 comments

Comments

@xlaussel
Copy link

xlaussel commented Jun 7, 2022

I try to use the router in a typescript + vite environnement.
I import the library like:

import {Routing} from '~/vendor/friendsofsymfony/jsrouting-bundle/Resources/public/js/router'

(~ is an alias to the root folder)

But when executing I have the following error in the console:
Uncaught SyntaxError: The requested module '/@fs/data/xlextent/srcs/financile/vendor/friendsofsymfony/jsrouting-bundle/Resources/public/js/router.js' does not provide an export named 'Routing' (at routing.ts:3:1)

When I do:

import Routing from '~/vendor/friendsofsymfony/jsrouting-bundle/Resources/public/js/router'

I have the error:

But when executing I have the following error in the console:
Uncaught SyntaxError: The requested module '/@fs/data/xlextent/srcs/financile/vendor/friendsofsymfony/jsrouting-bundle/Resources/public/js/router.js' does not provide an export named 'default' (at routing.ts:3:1)

Here is my tsconfig.json with esModuleInterop ans allowJs set:

{
  "extends": "@vue/tsconfig/tsconfig.web.json",
  "include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
  "compilerOptions": {
    "esModuleInterop": true,
    "allowJs": true,
    "paths": {
      "@/*": ["./src/*"],
      "~/*": ["../*"],
    }
  },

  "references": [
    {
      "path": "./tsconfig.config.json"
    }
  ]
}

What can I do?

@fatso83
Copy link

fatso83 commented Jun 28, 2022

So strange. It most definitely has a Router export, but I have not checked the transpiled code.

@r4pt0s
Copy link

r4pt0s commented Oct 18, 2024

I know this is a quite old issue but I came across the same problem.
If you use vite instead of webpack (or it doesn't matter I guess) you can simple import the router.ts file directly instead of using the transpiled js files.
If you yarn add or npm installed ./vendor/friendsofsymfony/jsrouting-bundle/Resources/ then you should be able to import the router.ts file with

import Routing from 'fos-router/js/router';

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

3 participants