fastify / fastify-dx

Archived
901 stars 42 forks source link

bug: wrong file path when creating route in monorepo #53

Open HigherOrderLogic opened 1 year ago

HigherOrderLogic commented 1 year ago

Prerequisites

Fastify version

4.11.0

Plugin version

@fastify/vite: ^3.0.4, @fastify/vue: ^@0.1.0

Node.js version

18.x

Operating system

Windows

Operating system version (i.e. 20.04, 11.3, 10)

10

Description

When building project inside monorepo, file path is wrong.

Error ```cmd vite v4.0.4 building for production... ✓ 11 modules transformed. Could not resolve "./project/name/app/frontend/D:/project/name/app/frontend/src/pages/index.vue" from "../../../../../dx:routes.js" file: /dx:routes.js error during build: RollupError: Could not resolve "./project/name/app/frontend/D:/project/name/app/frontend/src/pages/index.vue" from "../../../../../dx:routes.js" at error (file:///D:/project/name/node_modules/rollup/dist/es/shared/rollup.js:1967:30) at ModuleLoader.handleInvalidResolvedId (file:///D:/project/name/node_modules/rollup/dist/es/shared/rollup.js:23095:24) at file:///D:/project/name/node_modules/rollup/dist/es/shared/rollup.js:23058:26 ```

Steps to Reproduce

Expected Behavior

Build success.

dkamorin commented 1 year ago

Got similar error. My case is Win 10 and fresh boilerplate Vue project from this repo.

As I can see the issue happens in transformGlobImport method at node_modules/@fastify/vite/node_modules/vite/dist/node/chunks/dep-5605cfa4.js:35470, but I have no understanding how it can be fixed.

There's a row let importPath = relative(dir, file) in this method, where relative is POSIX method (defined in a code above). Finally for

dir='/'
file='C:/Users/myusername/projectname/client/pages/client-only.vue'

I get

importPath='Users/myusername/projectname/C:/Users/myusername/projectname/client/pages/client-only.vue'

Right now after number of hours I found that it works with

let importPath = path$o.relative(dir, file);

instead of

let importPath = relative(dir, file);

(where path$o.relative is cross-platform node:path method). But I don't know yet how to prepare this in PR.