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

Crash on Windows #52

Open
chengpeiquan opened this issue Jan 24, 2024 · 9 comments
Open

Crash on Windows #52

chengpeiquan opened this issue Jan 24, 2024 · 9 comments

Comments

@chengpeiquan
Copy link

Previous steps:

pnpm create vocs
cd vocs-demo
pnpm i
pnpm dev

Everything works fine up to here.

image

But when I open it in the browser (http://localhost:5173/) , file loading failure occurs. It seems to be caused by a slash problem in Windows.

image

I tried to provide a reproducible demo, but the online example of stackblitz doesn't seem to run from Windows.

@chengpeiquan
Copy link
Author

Tried it on my MacBook at home tonight and everything worked fine.
Since I use Windows at work during the day and only use macOS at home at night, I will continue to handle this problem during my lunch break at the company and try to help fix it.

@tmm
Copy link
Member

tmm commented Jan 24, 2024

That would be great! I don't have a Windows computer so would love to have a PR for this.

@dalechyn
Copy link
Contributor

dalechyn commented Feb 4, 2024

Hello, we faced the same issue on a Windows machine, tried to debug with no luck.

Similar issues: storybookjs/builder-vite#586, davidmyersdev/vite-plugin-node-polyfills#29

@chengpeiquan
Copy link
Author

Hello, we faced the same issue on a Windows machine, tried to debug with no luck.

Similar issues: storybookjs/builder-vite#586, davidmyersdev/vite-plugin-node-polyfills#29

I try to solve this problem in my free time, but the progress is currently slow (it is now before the Chinese New Year, and I am quite busy at work).

The most difficult problem for me at the moment is that I cannot recognize the file path pointed to in the virtual module, although the path is correct, but a similar crash problem still exists.

I also tried the solution mentioned in the Storybook issue, but it didn't work.

I will continue to try to find the cause of this problem when I'm on vacation in a few days.

@klepto
Copy link

klepto commented Feb 26, 2024

In this specific case, the problem is caused by using resolve from node:path module to generate imports in vite/plugins/virtual-styles.ts:

const themeStyles = resolve(__dirname, '../.vocs/themez.css')
const rootStyles = resolve(rootDir, 'styles.css')
let code = ''
if (existsSync(themeStyles)) code += `import "${themeStyles}";`
if (existsSync(rootStyles)) code += `import "${rootStyles}";`

The node:path module uses platform specific implementation, which means on Windows, it will produce paths with \ as the default separator, this ends up being incorrect import syntax hence the error.

Now as so happens Windows actually supports both separators equally, so any path using posix / separator is just as valid on Windows, which makes dependencies like https://www.npmjs.com/package/upath an easy drop-in solution.

You can of course try to address pathing problems individually without any external dependencies, but this most likely isn't the only instance where pathing issues exist. Fixing this specific case allowed my project to build, but the page still wasn't rendering properly.

I couldn't propose a PR request for this because I can't build vocs on Windows machine due to some dependencies not supporting Windows.

Looking forward to a fix! 😊

@klepto
Copy link

klepto commented Feb 28, 2024

@tmm ^

@tmm
Copy link
Member

tmm commented Feb 29, 2024

Feel free to submit a PR. I don't use Windows so I'm probably not the best person to work on this.

@chengpeiquan
Copy link
Author

In this specific case, the problem is caused by using resolve from node:path module to generate imports in vite/plugins/virtual-styles.ts:

const themeStyles = resolve(__dirname, '../.vocs/themez.css')
const rootStyles = resolve(rootDir, 'styles.css')
let code = ''
if (existsSync(themeStyles)) code += `import "${themeStyles}";`
if (existsSync(rootStyles)) code += `import "${rootStyles}";`

The node:path module uses platform specific implementation, which means on Windows, it will produce paths with \ as the default separator, this ends up being incorrect import syntax hence the error.

Now as so happens Windows actually supports both separators equally, so any path using posix / separator is just as valid on Windows, which makes dependencies like https://www.npmjs.com/package/upath an easy drop-in solution.

You can of course try to address pathing problems individually without any external dependencies, but this most likely isn't the only instance where pathing issues exist. Fixing this specific case allowed my project to build, but the page still wasn't rendering properly.

I couldn't propose a PR request for this because I can't build vocs on Windows machine due to some dependencies not supporting Windows.

Looking forward to a fix! 😊

I created a PR that fixed most of the crashes. See: #128

@chengpeiquan
Copy link
Author

Hello, we faced the same issue on a Windows machine, tried to debug with no luck.

Similar issues: storybookjs/builder-vite#586, davidmyersdev/vite-plugin-node-polyfills#29

I created a PR that fixed most of the crashes. See: #128

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

4 participants