fastify-dx icon indicating copy to clipboard operation
fastify-dx copied to clipboard

bug: wrong file path when creating route in monorepo

Open HigherOrderLogic opened this issue 3 years ago • 1 comments

Prerequisites

  • [X] I have written a descriptive issue title
  • [X] I have searched existing issues to ensure the bug has not already been reported

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
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

  • Folder structure:
app/
|
|_backend/
|	|_package.json
|	|_src/
|
|_frontend/
|	|_vite.config.ts
|	|_client/
|
|_package.json
|_node_modules/
  • Step to reproduce: Run build command inside frontend folder.

Expected Behavior

Build success.

HigherOrderLogic avatar Jan 10 '23 17:01 HigherOrderLogic

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.

dkamorin avatar Apr 11 '23 01:04 dkamorin