unjs / unbuild

📦 A unified JavaScript build system
MIT License
2.37k stars 91 forks source link

Failed to resolve stubed module #438

Open sadeghbarati opened 1 year ago

sadeghbarati commented 1 year ago

Environment

Node: 18.15.0 Windows 11

Reproduction

https://github.com/sadeghbarati/jiti-resolve-issue

Describe the bug

Failed to resolve stub module in Windows and also macOS environment

Additional context

I'm using unbuild --stub to use jiti feature in Dev mode

import jiti from "file:///D:/Sadegh/Test/unbuild-jiti-monorepo/node_modules/.pnpm/jiti@1.18.2/node_modules/jiti/lib/index.js";

/** @type {import("D:/Sadegh/Test/unbuild-jiti-monorepo/packages/lib/src/index")} */
const _module = jiti(null, { interopDefault: true, esmResolve: true })("D:/Sadegh/Test/unbuild-jiti-monorepo/packages/lib/src/index.ts");

export const test = _module.test;

Logs

No response

johannschopplich commented 1 year ago

Same issue experienced by me in the unlazy monorepo.

productdevbook commented 1 year ago

same ubuntu problem

jimmyann2023 commented 6 months ago

Had the same problem in monorepo

import jiti from "file:///C:/Users/Administrator/Desktop/dev/Turborepo/buildDemo/node_modules/.pnpm/jiti@1.21.0/node_modules/jiti/lib/index.js";

/* @type {import("C:/Users/Administrator/Desktop/dev/Turborepo/buildDemo/packages/ui/src/index")} / const _module = jiti(null, { "esmResolve": true, "interopDefault": true, "alias": { "@cd/ui": "C:/Users/Administrator/Desktop/dev/Turborepo/buildDemo/packages/ui" } })("C:/Users/Administrator/Desktop/dev/Turborepo/buildDemo/packages/ui/src/index.ts");

export const log = _module.log;

08:08:06 [vite] Pre-transform error: Failed to resolve import "file:///C:/Users/Administrator/Desktop/dev/Turborepo/buildDemo/node_modules/.pnpm/jiti@1.21.0/node_modules/jiti/lib/index.js" from "../../packages/ui/dist/index.mjs". Does the file exist? 08:08:06 [vite] Internal server error: Failed to resolve import "file:///C:/Users/Administrator/Desktop/dev/Turborepo/buildDemo/node_modules/.pnpm/jiti@1.21.0/node_modules/jiti/lib/index.js" from "../../packages/ui/dist/index.mjs". Does the file exist? Plugin: vite:import-analysis File: C:/Users/Administrator/Desktop/dev/Turborepo/buildDemo/packages/ui/dist/index.mjs:1:19 1 | import jiti from "file:///C:/Users/Administrator/Desktop/dev/Turborepo/buildDemo/node_modules/.pnpm/jiti@1.21.0/node_modules/jiti/lib/index.js"; | ^ 2 | 3 | /* @type {import("C:/Users/Administrator/Desktop/dev/Turborepo/buildDemo/packages/ui/src/index")} / at formatError (file:///C:/Users/Administrator/Desktop/dev/Turborepo/buildDemo/nodemodules/.pnpm/vite@5.2.11@types+node@20.12.11/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:50830:46) at TransformContext.error (file:///C:/Users/Administrator/Desktop/dev/Turborepo/buildDemo/nodemodules/.pnpm/vite@5.2.11@types+node@20.12.11/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:50824:19) at normalizeUrl (file:///C:/Users/Administrator/Desktop/dev/Turborepo/buildDemo/nodemodules/.pnpm/vite@5.2.11@types+node@20.12.11/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:66128:33) at async file:///C:/Users/Administrator/Desktop/dev/Turborepo/buildDemo/nodemodules/.pnpm/vite@5.2.11@types+node@20.12.11/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:66283:47 at async Promise.all (index 0) at async TransformContext.transform (file:///C:/Users/Administrator/Desktop/dev/Turborepo/buildDemo/nodemodules/.pnpm/vite@5.2.11@types+node@20.12.11/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:66204:13) at async Object.transform (file:///C:/Users/Administrator/Desktop/dev/Turborepo/buildDemo/nodemodules/.pnpm/vite@5.2.11@types+node@20.12.11/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:51139:30) at async loadAndTransform (file:///C:/Users/Administrator/Desktop/dev/Turborepo/buildDemo/nodemodules/.pnpm/vite@5.2.11@types+node@20.12.11/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:53894:29) at async viteTransformMiddleware (file:///C:/Users/Administrator/Desktop/dev/Turborepo/buildDemo/nodemodules/.pnpm/vite@5.2.11@types+node@20.12.11/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:63743:32)