vikejs / vike

🔨 Flexible, lean, community-driven, dependable, fast Vite-based frontend framework.
https://vike.dev
MIT License
4.4k stars 353 forks source link

✘ [ERROR] Plugin "vike-esbuild" returned a path in the "file" namespace that is not an absolute path: #1882

Closed brillout closed 2 months ago

brillout commented 2 months ago

Description

From PM:

it seems like vike-esbuild can't transpile the imports, which in our ESM monorepo setup point to a file in the framework (taproot) workspace:

14:25:59 [vike][config] Failed to transpile /src/renderer/+passToClient.js because: ✘ [ERROR] Plugin "vike-esbuild" returned a path in the "file" namespace that is not an absolute path: @ecosia/taproot/renderer/server/passToClient.js

also tried to change +passToClient.js into +config.js and export { passToClient: […] } config object; no luck, the import is still not processed.

brillout commented 2 months ago

@LostCrew Active the debug logs with DEBUG=vike:pointer-imports npm run ... and report back the logs.

LostCrew commented 2 months ago

Setup: yarn v1 with workspaces (yes, we are aware that, at this point, any other more modern package manager is better 😢), ESM, Node v20.2.x.

Output:

11:31:54 [vike][config] Failed to transpile /src/renderer/+passToClient.js because:
✘ [ERROR] Could not resolve "redacted_path_to_framework/renderer/server/passToClient.js" [plugin vike-esbuild]

    src/renderer/+passToClient.js:1:25:
      1 │ ...assToClient from 'redacted_path_to_framework/renderer/server/passToClient.js';
        ╵                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Also:

11:31:54 [vike][Warning] Update to the new V1 design to get rid of Vite's warning: The glob option "as" has been deprecated in favour of "query". See https://vike.dev/migration/v1-design for how to migrate.
The glob option "as" has been deprecated in favour of "query". Please update `as: 'extractExportNames'` to `query: '?extractExportNames'`.

From yarn.lock, package versions that might be useful to know:

Error does not occur for imports in other Vike-handled files (+onRenderHtml.js, +onRenderClient.js). Exporting hardcoded values, thereby renouncing to importing them from a common place and repeating it on all Vike-powered apps, successfully circumvent the issue but it is very not ideal in terms of duplicated mantainance points.

Perhaps a non-deterministic incompatible version of ESBuild is used? In that case, we could try lock the esbuild version to a compatible one as resolution in root package.json.

Thanks for advising 👍🏻

brillout commented 2 months ago

Your last output is a different error than the error I quoted in my original post, and it seems unrelated to Vike.

Also, the debug logs (DEBUG=vike:pointer-imports) are missing. You should get logs like the following:

vike:pointer-imports code, no transformImports() (/renderer/+config.ts)
vike:pointer-imports transpile /pages/star-wars/@id/+dataIsomorph.ts
vike:pointer-imports code, post esbuild (/pages/star-wars/@id/+dataIsomorph.ts)

The best would be that you reproduce the original error and share the debug logs.

LostCrew commented 2 months ago

True, the state of the imports when running the above command was transitional and I thought the flag was set for the session, but wasn't.

Here is the output of yarn dev ran with the flag set and the import pointing to an existing file from the yarn workspace of the framework that encapsulate Vike (once again, real framework npm package name redacted to @ecosia/framework for privacy and security):

vike:pointer-imports transpile /src/renderer/+passToClient.js
vike:pointer-imports onResolved()
                     {
                       "args": {
                         "path": "@ecosia/framework/renderer/server/passToClient",
                         "importer": "/Users/emanuele/Code/core/search/settings/src/renderer/+passToClient.js",
                         "namespace": "file",
                         "resolveDir": "/Users/emanuele/Code/core/search/settings/src/renderer",
                         "kind": "import-statement",
                         "with": {}
                       },
                       "resolved": {
                         "errors": [],
                         "warnings": [],
                         "path": "/Users/emanuele/Code/core/framework/renderer/server/passToClient.js",
                         "external": false,
                         "sideEffects": true,
                         "namespace": "file",
                         "suffix": ""
                       },
                       "importPathTranspiled": "@ecosia/framework/renderer/server/passToClient",
                       "isPointerImport": false,
                       "isExternal": false
                     }
09:39:36 [vike][config] Failed to transpile /src/renderer/+passToClient.js because:
✘ [ERROR] Plugin "vike-esbuild" returned a path in the "file" namespace that is not an absolute path: @ecosia/framework/renderer/server/passToClient

    src/renderer/+passToClient.js:1:25:
      1 │ ...t passToClient from '@ecosia/framework/renderer/server/passToClient';
        ╵                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
brillout commented 2 months ago

@ecosia/framework for privacy and security

Can you PM me the real one? This may very well be the issue.

brillout commented 2 months ago

@ecosia/framework for privacy and security

Can you PM me the real one? This may very well be the issue.

Or, alternatively, publish a reproduction.

LostCrew commented 2 months ago

You now have a new PM

brillout commented 2 months ago

Can you try vike@0.4.195-commit-c68b18f? I believe that should fix it.

brillout commented 2 months ago

Fix released in 0.4.196.