FriendsOfSymfony / FOSJsRoutingBundle

A pretty nice way to expose your Symfony routing to client applications.
1.48k stars 260 forks source link

TS2732: Cannot find module './routes.json'. Consider using '--resolveJsonModule' to import module with '.json' extension. #477

Closed ovi1337 closed 3 months ago

ovi1337 commented 3 months ago

I'm using Symfony 6.4.4 with symfony/webpack-encore-bundle v2.1.1 and friendsofsymfony/jsrouting-bundle v3.5.0 The Typescript-Loader is also enabled.

i've actually started a fresh project with nothing special and i'm getting the following issue:

Running webpack ...

Executing pre-build scripts
Dumping exposed routes.

[file+] public/js/fos_js_routes.json
 ERROR  Failed to compile with 1 errors                                                                                                                                                 7:02:28 PM

 error  in ./vendor/friendsofsymfony/jsrouting-bundle/Resources/ts/router.test-d.ts:4:20                                                                                                7:02:28 PM

TS2732: Cannot find module './routes.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.
    2 | import type { RoutesMap } from '../js/router';
    3 | import { type Route, Router, Routing } from './router';
  > 4 | import routes from './routes.json';
      |                    ^^^^^^^^^^^^^^^
    5 |
    6 | expectType<Router>(Router.getInstance());
    7 | expectType<Router>(Routing);

Entrypoint app [big] 708 KiB = runtime.js 14.6 KiB vendors-node_modules_symfony_stimulus-bridge_dist_index_js-node_modules_fos-router_public_js_-37d634.js 669 KiB app.css 972 bytes app.js 23.8 KiB
webpack compiled with 1 error

Process finished with exit code 1

the relevant webpack.config.js part looks currently like this:

...
.addPlugin(
        new WebpackShellPluginNext({
            //dev: true,
            onBuildStart: {
                scripts: [
                    'bin/console fos:js-routing:dump --format=json --target=public/js/fos_js_routes.json',
                ],
                blocking: true,
                parallel: false
            },
        }),
    )
    .addPlugin(new FosRouting())
...

But i can also remove both plugins and getting the same issue. The Export works as expected and the file is also generated.