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

Windows pathing issue on dev / build #684

Closed
Hecatron opened this issue Nov 21, 2022 · 24 comments
Closed

Windows pathing issue on dev / build #684

Hecatron opened this issue Nov 21, 2022 · 24 comments
Assignees

Comments

@Hecatron
Copy link

Hi,
It looks as if there's an issue when running yarn dev or yarn build under windows
Seems to be some sort of pathing issue

√ Using Nuxt Typography v0.0.17                                                                                                                                 17:37:40
i Client built in 4227ms                                                                                                                                        17:37:51
i Building server...                                                                                                                                            17:37:51
√ Server built in 3795ms                                                                                                                                        17:37:55
√ Generated public .docs/.output/public                                                                                                                   nitro 17:37:55
i Initializing prerenderer                                                                                                                                nitro 17:37:55

 ERROR  Only URLs with a scheme in: file, data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'

  at new NodeError (node:internal/errors:377:5)
  at throwIfUnsupportedURLScheme (node:internal/modules/esm/resolve:1076:11)
  at defaultResolve (node:internal/modules/esm/resolve:1156:3)
  at ESMLoader.resolve (node:internal/modules/esm/loader:605:30)
  at ESMLoader.getModuleJob (node:internal/modules/esm/loader:318:18)
  at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:80:40)
  at link (node:internal/modules/esm/module_job:78:36)

I think it's related to the drive letter C: or D: in the path, although I've not been able to tie down exactly which bit of code is the problem.

It's the same issue mentioned here #681 by KyleRicardo

someone else also mentioned it here - nuxt-themes/docus-docs-starter#7

@phenomen
Copy link

phenomen commented Nov 21, 2022

The same, Windows 11. I've tried npm and pnpm.

@zoey-kaiser
Copy link

zoey-kaiser commented Nov 21, 2022

I will raise my comment from #681 here again. We had the same issue with Windows reading URL schemas differently then Mac or Linux. If it helps you can see how we approached the fix here:

sidebase/nuxt-session#13

@Tahul
Copy link
Contributor

Tahul commented Nov 21, 2022

Hey;

I will have access to a desktop env on Windows tomorrow, will try to solve that issue as soon as possible.

Could @phenomen or @grbd point out what kind of environments are you running in?

Windows terminal? WSL?

Thank you a lot and sorry for the inconvenience. 🙏

@Hecatron
Copy link
Author

In my case it's windows 10 21H2
Tried from both a vanilla command prompt and a visual studio 2022 developer command prompt (same as a regular one but with additional tools installed)

Based on the above comments I'm guessing there's a import { resolve } from 'path' in a dependency some place that needs replacing with a

import { createResolver } from '@nuxt/kit'
const { resolve } = createResolver(import.meta.url)

similar to what's already done in the nuxt.config.ts
although the stack trace I'm getting isn't giving me any clues as to where it is other than it happening after the prerenderer

@Tahul
Copy link
Contributor

Tahul commented Nov 21, 2022

@grbd ; I've published this commit Tahul/pinceau@5a8b4e9

I was using resolve from path and replaced it with pathe.

This might help on this issue, could you try reinstalling all dependencies with fresh lockfile?

Not sure this will help but it is first step.

Thanks 🙏

@Hecatron
Copy link
Author

I tried doing a fresh clone to avoid any cache's or lock files being an issue

git clone https://github.com/nuxt-themes/docus
cd docus
yarn install

Then a yarn build / yarn dev (which tries to build inside .docs) but the result is still the same error sorry
also I double checked the version of pinceau was 0.6.26 the one you've just updated

Error is still

 ERROR  [worker reload] [worker init] Only URLs with a scheme in: file, data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'

  at new NodeError (node:internal/errors:377:5)
  at throwIfUnsupportedURLScheme (node:internal/modules/esm/resolve:1076:11)
  at defaultResolve (node:internal/modules/esm/resolve:1156:3)
  at ESMLoader.resolve (node:internal/modules/esm/loader:605:30)
  at ESMLoader.getModuleJob (node:internal/modules/esm/loader:318:18)
  at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:80:40)
  at link (node:internal/modules/esm/module_job:78:36)

@Tahul
Copy link
Contributor

Tahul commented Nov 21, 2022

I'm afraid we'll have to wait for me to have access to a Windows environment.

Thank you so much for the quick answer though.

I hope to fix this tomorrow, without being able to track which line throws this error I won't be able to fix this.

@MrSociety404
Copy link

Nuxt/i18n had the same issue recently nuxt-modules/i18n#1518

They change the absolute path by a relative path with an assert type.

Hope it can help you

@Hecatron
Copy link
Author

Hecatron commented Nov 22, 2022

Just spotted a few places its showing up in the generated files under the .nuxt build directory

docus\.docs\.nuxt\app.config.mjs

import { defuFn } from 'C:/D/Temp/18/test3/docus/node_modules/defu/dist/defu.mjs'

const inlineConfig = {}

import cfg0 from "C:/D/Temp/18/test3/docus/.docs/app.config.ts"
import cfg1 from "C:/D/Temp/18/test3/docus/app.config.ts"
import cfg2 from "C:/D/Temp/18/test3/docus/node_modules/@nuxt-themes/typography/app.config.ts"

export default defuFn(cfg0, cfg1, cfg2, inlineConfig)

docus\.docs\.nuxt\dev\index.mjs

...
import _OxsnGi2RuD from 'C:/D/Temp/18/test3/docus/node_modules/pinceau/dist/nitro';
...

an entry within docus\.docs\.nuxt\dist\server\server.mjs.map

docus\.docs\.nuxt\prerender\chunks\nitro-prerenderer.mjs

...
import _OxsnGi2RuD from 'C:/D/Temp/18/test3/docus/node_modules/pinceau/dist/nitro';
...

all of these actually need to be file://C:/Path instead, and it looks like there's a lot of them that already are in the same files nearby, so it's problably a one liner some place

@Tahul
Copy link
Contributor

Tahul commented Nov 22, 2022

Hey @grbd ;

That is immensely helpful, I suggest there is some issues in path resolving upstream.

@danielroe ; I've only identified this line in Nitro that seem not to use pathe:
https://github.com/unjs/nitro/blob/ffcbdbb2c65e43da1e985f952a25859ab298a140/src/runtime/entries/nitro-dev.ts#L4

Any idea on what could be the source of this? I would happily work on a PR to solve it.

Here is some code pointers that might help on digging:

In the meantime I'm afraid I'll have to suggest running it in WSL.

rekryt added a commit to rekryt/docus that referenced this issue Nov 22, 2022
Windows pathing issue on dev / build nuxt-themes#684
nuxt-themes#684

This is partial fix for windows problem
@rekryt
Copy link

rekryt commented Nov 22, 2022

After fix #686 at https://github.com/nuxt-themes/docus/blob/dev/app/module.ts#L5
only these broken pathes remain:
image

image

@Hecatron
Copy link
Author

Hecatron commented Nov 22, 2022

So for the plugin line
https://github.com/Tahul/pinceau/blob/e99c19bbca4ef4626c59d35bbd5bf652df6d2753/src/nuxt.ts#L44

// I tried swapping
nuxt.options.nitro.plugins.push(modulePath.resolve('./nitro'))
// with an absolute path
nuxt.options.nitro.plugins.push('file:///C:/D/SourceCode/Forks/pinceau/dist/nitro')

However the path then ends up getting treated as a relative path and gets a bit mangled
Cannot find module 'C:\D\Temp\18\.docs\server\file:\C:\D\SourceCode\Forks\pinceau\dist\nitro' imported from C:\D\Temp\18\test3\docus-orig\.docs\.nuxt\prerender\index.mjs

So the next question is whereabouts it's getting parsed ether in nuxt or nitro
kinda wish there was a way to enable longer stacktraces in nuxt

@Hecatron
Copy link
Author

Update, commenting that one line that adds the pinceau nitro plugin
https://github.com/Tahul/pinceau/blob/e99c19bbca4ef4626c59d35bbd5bf652df6d2753/src/nuxt.ts#L44

Allows us to get some semblence of an output we can preview

# switched to pnpm to get everything to build and link together during debugging
pnpm build
pnpm preview

But dev just hangs (probably because we're missing the plugin)

pnpm dev

I think the issue is someplace within nitro, I finally managed to get the depends to build and link together so more digging required.

@Tahul
Copy link
Contributor

Tahul commented Nov 23, 2022

@grbd ; are you saying the build passes with pnpm build and pnpm preview but dev is broken ?

@Hecatron
Copy link
Author

Hecatron commented Nov 23, 2022

@grbd ; are you saying the build passes with pnpm build and pnpm preview but dev is broken ?

Only if that line is commented out which removes the nitro plugin but that's not really a fix just an observation
I think I've discovered one of the problems in nitro so I've added a pull request for that
although we also need to add the .mjs extension to the path below within pinceau

# This
nuxt.options.nitro.plugins.push(modulePath.resolve('./nitro'))
# instead needs to be something like this
nuxt.options.nitro.plugins.push(modulePath.resolve('./nitro.mjs'))

Not sure if there's a better way but overall it gets us a little bit further along

After the above this then leads to some sort of issue with the way a nuxt module is being imported

 ERROR  Package import specifier "#color-mode-options" is not defined in package C:\D\Temp\18\test3\docus-orig\node_modules\.pnpm\@nuxtjs+color-mode@3.1.8\node_modules\@nuxtjs\color-mode\package.json imported from C:\D\Temp\18\test3\docus-orig\node_modules\.pnpm\@nuxtjs+color-mode@3.1.8\node_modules\@nuxtjs\color-mode\dist\runtime\nitro-plugin.mjs

which I think is another nitro plugin issue (there's two one for pinceau which seems to work ok after the above fixes and a 2nd one associated with nuxtjs color-mode causing this problem)

@florian-lefebvre
Copy link

I'm encountering the same issue using pnpm dev on Windows 11

@aliosmandev
Copy link

i also encountered the same problem

@sdsoldi
Copy link

sdsoldi commented Nov 25, 2022

Same here with win10

@Tahul
Copy link
Contributor

Tahul commented Nov 27, 2022

Hey :)

Could you try regenerating your lockfiles to grab latest version of Pinceau, using Docus ^1.0.1?

I finally had access to a Windows dev environment and fixed it today!

@sdsoldi @osmandlsmn @florian-lefebvre @grbd @zoey-kaiser @rekryt ; let me know if it solves your issues :)

@rekryt
Copy link

rekryt commented Nov 27, 2022

@Tahul , yes, everything is fine, thank you!!👍

@florian-lefebvre
Copy link

Same here 👍

@Hecatron
Copy link
Author

Very cool works like a charm checked build, dev, preview
I'll close the issue down now

@sdsoldi
Copy link

sdsoldi commented Nov 28, 2022

Working on win10. thank you!! 👏

Copy link
Contributor

Tahul commented Nov 28, 2022

So happy it fixed it for all of you, have fun documenting! 🙂

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

No branches or pull requests

9 participants