-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Failed to load vite.config.js during build - Cannot use import statement outside a module #12923
Comments
Hello @lorand-horvath. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with |
I ran into this same error today as well. Did more Github searching and stumbled on this #4833 (comment) So, in my particular case, this is related to the fact that I was executing My quick fix was to navigate to the target directory and run This is obviously less than ideal however, and this should still be considered a regression. |
It happend to me too. I thought it was related to my latest upgrade of nodejs to v20.0.0, but it still occurred when I reverted back to v18.16.0. What I did after the node update, I deleted my node_modules folder and ran "node update" to reinstall the packages. I found that I was originally on vite v4.2.2 and it updated to v4.3.1 since my package.json was looking for "vite": "^4.0.0". I took vite back to v4.3.0 and still had the issue. So I went back to v4.2.2 since I did not want to walk thru all the 4.3 beta All are working so far. Environment: Laravel Version - v10.8.0 |
@nickturrietta In my case it was not a mapped drive in question. I have local, regular drives in my Windows machine. However, I've found a simple solution: renamed |
Run into the same issue. Even the file path is case-sensitive now. |
The same path case-sensitive thing actually happens to |
worked switching back to 4.2.2
|
Just rename to |
Doesn't help in my case, just throws another error:
|
It depends what version of Laravel and/or laravel-vite-plugin you have. According to the laravel-vite-plugin documentation for laravel 10 https://laravel.com/docs/10.x/vite#configuring-vite in vite.config.(m)js you should have something like:
which I assume it expects for laravel to have an ES module with |
The renaming option did not work for me either. It fails in my current fixed vite v4.2.2., downgraded from 4.3.1 that I had issues with. I received the error below after renaming vite.config.js to vite.config.mjs:
All of my paths case-sensitivity match, so that is not an issue for me. I also do not have any drives/folders mapped or linked. My environment and vite.config.js are below and I am still on vite v4.2.2..
Maybe this will help.... |
I encountered this problem as well. Only solution that worked was to downgrade vite to 4.2.2. Laravel 10 with Inertia/VueJS on a windows machine, only local drives. It was working fine earlier today, it had stopped working on a later dev session today for some reason. |
Same problem.
|
@sapphi-red I'm not sure about ppls here using laravel, but for me, on windows using PowerShell, if the file path does NOT match in terms of lower or upper case, then it leads to the issue we are discussing here, but unfortunately, I cannot reproduce it in StackBlitz since it's not windows so it doesn't allow same path but with different case: |
@xsjcTony Can confirm. Windows, cmd. |
@sapphi-red I can't reproduce on another device either which is weird. The only difference is Node version (16 vs 18), But for this one vitest-dev/vitest#2962 (comment), I can reproduce it on all my devices. Not sure if they are possibly related or not |
@sapphi-red Reproduction steps:
I did not have this issue with Vite 4.2.2, so npm run build was working with the default vite.config.js. |
I'm also seeing this issue with https://github.com/fwouts/previewjs although it's not happening in CI. I wonder if it's to do with the file system being configured to be case sensitive or not? I tried a few different Vite versions, here are the results:
Given this, I assume the culprit is in v4.3.0-beta.0...v4.3.0-beta.1. Perhaps #12580? Edit: I tried reverting #12580 locally on top of 4.3.1 and I don't think it resolves it. |
Here is the full error stack I'm seeing:
This is with a Update: confirmed, both sides of the equality check have a different casing:
|
@fwouts Great find! I think renaming cc: @patak-dev @bluwy Please take a look at this, now that the bug has been found. |
Issue persists with latest Vite 4.3.2. |
I reproduced by using CMD. It seems powershell normalizes |
@sapphi-red Are you able to reproduce my case? I'm using Terminal App ( I don't have |
@xsjcTony No, your case didn't reproduce on my computer. |
Thanks for testing @sapphi-red but never mind since it has been resolved in the latest release. |
|
@CatLeeran No need for that, since the bug has been fixed in Vite 4.3.3 via #13005 |
Describe the bug
I'm trying to
npm run build
with the latest Vite 4.3 having a package.json without "type": "module" specified in it and I get the following error:I'm using the default vite.config.js created via
npm create vue@latest
and the import/export statements in it should be pre-processed according to the documentation https://vitejs.dev/config/ but it seems to be failing.Note Vite supports using ES modules syntax in the config file even if the project is not using native Node ESM, e.g. type: "module" in package.json. In this case, the config file is auto pre-processed before load.
Reverting to vite@4.2.2 fixes the issue.
Reproduction
https://vitejs.dev/config/
Steps to reproduce
npm create vue@latest
npm install
npm run build
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: