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

Problem with Vite and symlinks #15036

Open
probert94 opened this issue Nov 8, 2022 · 3 comments
Open

Problem with Vite and symlinks #15036

probert94 opened this issue Nov 8, 2022 · 3 comments
Assignees
Labels

Comments

@probert94
Copy link

Description of the bug

In my current setup, I use symlinks for a vaadin project located on another drive.
Examle:
C:\Dev\VaadinProject -> The real project
D:\Dev\VaadinProject -> The symlink

In IntelliJ, I am using the symlink project located under D:\Dev\VaadinProject.
This setup worked fine until we updated to Vaadin 23 and started using Vite but now I get the following error:
com.vaadin.flow.server.ServiceException: java.net.ConnectException: Connection refused: no further information

It seems like the vite server started but stopped after an error, which is printed to the console:

TypeError: Cannot read properties of undefined (reading 'imports')
at runOptimizeDeps (file:///C:/Dev/VaadinProject/node_modules/vite/dist/node/chunks/dep-665b0112.js:42330:89)
at processTicksAndRejections (node:internal/process/task_queues:96:5)

After some debugging, I found that a resource should be loaded from D:\Dev\VaadinProject\fakt\node_modules and that does not seem to be allowed (missing in server.fs.allow).
The allowed folders come from the vite.generated.ts and are the following:

'D:\\Dev\\VaadinProject\\frontend',
'C:\\Dev\\VaadinProject\\target\\flow-frontend',
'C:\\Dev\\VaadinProject\\target\\frontend',
'C:\\Dev\\VaadinProject\\node_modules'

As you see, only frontend is allowed to be loaded from D:\, all other folders need to be loaded using C:\.
The reason for this seems to be, that __dirname, which is used to calculate the paths, already resolves the symlink (see nodejs/node#22602).
The first allowed path (frontendFolder) comes from settings.frontendFolder and is an absolute path, using D:\,
The other 3 are relativ paths (addonFrontendFolder from vaadin-dev-server-settings.json is target/flow-frontend) and are resolved using __dirname and therefor use the wrong path.

Minimal reproducible example

  • Download a new vaadin starter project
  • Create a symlink for it (on windows 10 use powershell and following command: ni D:\Dev\VaadinProject-i SymbolicLink -ta C:\Dev\VaadinProject\
  • Start the project and open the browser

After the front-end is build, you get an error page instead of the application page.

Expected behavior

The application should start normaly.

Actual behavior

An error is shown

Versions:

- Vaadin / Flow version: 23.2.7
- Java version: Java 17.0.4
- OS version: Windows 10
- IDE (if applicable): IntelliJ Idea
- Development or production mode: Development mode
@probert94 probert94 added the vite Tickets related to vite support label Nov 8, 2022
@Artur-
Copy link
Member

Artur- commented Nov 8, 2022

Does it work when you add the folder to server.fs.allow in your vite.config.ts ?

@probert94
Copy link
Author

Yes that seems to work.
I had to add all folders with C:\ and D:\ and start the server. After that it seems to be enough to allow all folders for D:\.
Might have been some caching problem...
Unfortunately this is not a solution, as there are multiple people working on this project and others might use different folder structure.

@Artur-
Copy link
Member

Artur- commented Nov 15, 2022

If you do this on a mac

npx @vaadin/cli init test-proj
ln -s test-proj test-link
cd test-link
mvn

then all the entries of server.fs.allow point to the real project directory (test-proj) and all resources are also loaded from there so everything works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 🔖 Normal Priority (P2)
Development

No branches or pull requests

6 participants