Closed ivarlovlie closed 2 years ago
Hey thanks for reporting this! Will take a look later today what could cause this 🤔
@ivarlovlie Would you be able to provide a reproduction?
Also it would be good to know what node version you are using.
Ive tried to replicate the issue with node 16
, npm 8
and vite 2.8.6 and dont run into the same Issue!
repro: repro.zip
I am able to build the repro project when i'm on 0.8.7 of vite-aliases, and unable on 0.9.1.
using versions node: v17.1.0 pnpm: 6.23.2 npm: 8.1.2
I did a test reproduction in this git repo here: https://github.com/Subwaytime/vite-aliases-test - edit: not needed anymore
It works flawlessly for me, even tried pnpm.
used pnpm: 6.32.3 (latest)
Cant seem to replicate your Issue. What operating system do you use?
It looks to me this could be an issue with node 17
compared to node 16
. So if you could try using 16 for a test that would be great.
I am using Ubuntu 20.04 Tried with node 16.14.0 but still see the same behaviour using vite-aliases 0.9.1.
Cant seem to replicate your Issue
You're not able to reproduce on the project inside of repro.zip?
After further troubleshooting i managed to build with 0.9.1 by removing type: "module"
from package.json. Would it be worth looking into why type: "module"
worked with 0.8.7 but not with 0.9.1?.
Yeah so the type in package forces the build/dev to be in esm rather then cjs. I am checking now whether this is due to vite-aliases or a change in fast-glob, as this is reporting the error.
esm is technically still experimental on nodejs 16+, so you might run into troubles with this anyways. normally its not recommended, i will see if i can get vite-aliases to support it, or atleast find a work around if fast-glob is causing the issue.
Just wanted to say I was getting the same error. Tried going down to 16.14.2 of node and that didn't help. Was on 9.1 but upgraded to 9.2 of vite-aliases and it built. Is this then resolved? Below was the error I was getting if it were to be any help if it's not resolved.
error when starting dev server: Error: Dynamic require of "path" is not supported at file:///Users/jessecoble/Repositories/PLAYGROUND/SvelteTemplate/SvelteTemplate/node_modules/vite-aliases/dist/index.mjs:30:9 at node_modules/fast-glob/out/utils/path.js (file:///Users/jessecoble/Repositories/PLAYGROUND/SvelteTemplate/SvelteTemplate/node_modules/vite-aliases/dist/index.mjs:131:16) at require2 (file:///Users/jessecoble/Repositories/PLAYGROUND/SvelteTemplate/SvelteTemplate/node_modules/vite-aliases/dist/index.mjs:36:50) at node_modules/fast-glob/out/utils/index.js (file:///Users/jessecoble/Repositories/PLAYGROUND/SvelteTemplate/SvelteTemplate/node_modules/vite-aliases/dist/index.mjs:3235:16) at __require2 (file:///Users/jessecoble/Repositories/PLAYGROUND/SvelteTemplate/SvelteTemplate/node_modules/vite-aliases/dist/index.mjs:36:50) at node_modules/fast-glob/out/managers/tasks.js (file:///Users/jessecoble/Repositories/PLAYGROUND/SvelteTemplate/SvelteTemplate/node_modules/vite-aliases/dist/index.mjs:3253:17) at require2 (file:///Users/jessecoble/Repositories/PLAYGROUND/SvelteTemplate/SvelteTemplate/node_modules/vite-aliases/dist/index.mjs:36:50) at node_modules/fast-glob/out/index.js (file:///Users/jessecoble/Repositories/PLAYGROUND/SvelteTemplate/SvelteTemplate/node_modules/vite-aliases/dist/index.mjs:5167:23) at __require2 (file:///Users/jessecoble/Repositories/PLAYGROUND/SvelteTemplate/SvelteTemplate/node_modules/vite-aliases/dist/index.mjs:36:50) at file:///Users/jessecoble/Repositories/PLAYGROUND/SvelteTemplate/SvelteTemplate/node_modules/vite-aliases/dist/index.mjs:5240:32
I'm sorry, i actually downgraded to 8.6 of vite-aliases and that worked. I thought that's what I did but my package.json was showing 9.2 for some reason. I stopped and tried to restart the dev server and got the error again. Tried downgrading to 8.6 again, this time it "took" and showed as 8.6 in package.json and was then able to start the dev server. Sorry for the confusion.
Hmm thats interesting, are you using "type":"module"
in your package.json too? or without it?
Ya. I tried taking it out and just got a bunch more errors. I don't know a whole lot about bundlers, config files etc. Just been learning more about them, especially Vite. There's something special about it that just really intrigues me. I guess its just the pure speed of it and how it can build 100x faster than other bundlers. Anyways, if you need anymore info let me know. Be happy to help.
vite
and vite-aliases
should both run without "type":"module"
. If you dont have any other plugins installed that need this configuration specifically!
Ive been working on th ESM support, but it will still take some time, as other Bugfixes need to get implemented first!
sorry for the late response
+1 this issue - node v16.14.2, with type=module . v0.8.6 works Thx for the project though!
fix is coming with the newest release!
quick note: due to covid i wasnt able to work on this again, but now i can finally continue!
also, i will bundle this with the upcoming major changes from vite 3!
@Aurorxa thanks for that link, i have already updated these according to the docs, there are just some other bugs that currently interfere with a release
@Subwaytime I had this same issue recently with new Vite project and removing "type": "module" fixed the issue.
Add the below code in the 'vite.config.ts' or 'vite.config.js' file:
import { resolve } from 'path';
export default defineConfig({
resolve: {
alias: {
'@': resolve(__dirname, './src')
},
},
plugins: [vue()],
})
In my case I just change
const path = require('path')
to
import path from 'path'
and works.
@Subwaytime Is there still a planned fix so "type": "module" doesn't have to be removed from package.json?
if package.json
"type": "module",
then vite.config.js
import path from 'path';
if package.json
"type": "module",
then vite.config.jsimport path from 'path';
this solution works with node v20.8.0
Hi, great work on this!
After updating from 0.8.7 to 0.9.1 i get the following error when building:
working: working.zip repro: repro.zip
using versions vite: 2.8.6 node: v17.1.0 pnpm: 6.23.2 npm: 8.1.2