Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: next.config.js fails jiti imports on windows. #885

Closed
Cuhadari-Deniz opened this issue Feb 12, 2024 · 0 comments · Fixed by #886
Closed

bug: next.config.js fails jiti imports on windows. #885

Cuhadari-Deniz opened this issue Feb 12, 2024 · 0 comments · Fixed by #886

Comments

@Cuhadari-Deniz
Copy link
Contributor

Provide environment information

System:
OS: Windows 11 10.0.22631
CPU: (12) x64 AMD Ryzen 5 5600X 6-Core Processor
Memory: 13.21 GB / 31.93 GB
Binaries:
Node: 20.11.0 - C:\Program Files\nodejs\node.EXE
npm: 10.2.4 - C:\Program Files\nodejs\npm.CMD
pnpm: 8.15.1 - ~\AppData\Roaming\npm\pnpm.CMD

Describe the bug

_jiti(new URL(import.meta.url).pathname) fails on windows.

Link to reproduction

https://github.com/Cuhadari-Deniz/create-t3-turbo-issue-jiti-windows-compatibility

To reproduce

create a new project with pnpm create turbo@latest -e https://github.com/t3-oss/create-t3-turbo on windows.
Setup env variables.
Run pnpm dev in Windows Powershell.

Creating the following error:

@acme/nextjs:dev: node:internal/modules/cjs/loader:1144
@acme/nextjs:dev: const err = new Error(message);
@acme/nextjs:dev: ^
@acme/nextjs:dev:
@acme/nextjs:dev: Error: Cannot find module './src/env'
@acme/nextjs:dev: Require stack:
@acme/nextjs:dev: - \C:\Users\myWindowsUser\dev\playground\test\apps\nextjs\next.config.js
@acme/nextjs:dev: at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
@acme/nextjs:dev: at C:\Users\myWindowsUser\dev\playground\test\node_modules\next\dist\server\require-hook.js:55:36
@acme/nextjs:dev: at Function.resolve (node:internal/modules/helpers:187:19)
@acme/nextjs:dev: at _resolve (C:\Users\myWindowsUser\dev\playground\test\node_modules\jiti\dist\jiti.js:1:251148)
@acme/nextjs:dev: at jiti (C:\Users\myWindowsUser\dev\playground\test\node_modules\jiti\dist\jiti.js:1:253746)
@acme/nextjs:dev: at file:///C:/Users/myWindowsUser/dev/playground/test/apps/nextjs/next.config.js:11:1
@acme/nextjs:dev: at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
@acme/nextjs:dev: at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
@acme/nextjs:dev: at async importModuleDynamicallyWrapper (node:internal/vm/module:431:15)
@acme/nextjs:dev: at async loadConfig (C:\Users\myWindowsUser\dev\playground\test\node_modules\next\dist\server\config.js:706:36) {
@acme/nextjs:dev: code: 'MODULE_NOT_FOUND',
@acme/nextjs:dev: requireStack: [
@acme/nextjs:dev: '\C:\Users\myWindowsUser\dev\playground\test\apps\nextjs\next.config.js'
@acme/nextjs:dev: ]
@acme/nextjs:dev: }
@acme/nextjs:dev:
@acme/nextjs:dev: Node.js v20.11.0
@acme/nextjs:dev:  ELIFECYCLE  Command failed with exit code 1.
@acme/nextjs:dev:  ELIFECYCLE  Command failed with exit code 1.

Additional information

Running it with WSL2 is a working workaround.
I already fixed it locally and would love to make my first contribution to this project.

My fix:

let path = new URL(import.meta.url).pathname;

if (process.platform === "win32") {
  path = path.replace(/^\/(\w):/, "$1:");
}
const jiti = _jiti(path);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant