Next.js Discord

Discord Forum

Module Not Found.

Unanswered
Bengal posted this in #help-forum
Open in Discord
BengalOP
Everytime I create a new nextjs project I get this error. Any idea what could have caused this?:blob_help:

322 Replies

BengalOP
Okay so I removed the .next file and ran "npm run dev"
Same error
Actually got this first
Then the same error
What is your nextjs version
Upgrade to latest if you are not in latest version
BengalOP
13.4.19
used this command: npx create-next-app@latest
Project was created less than an hour ago.
Node js is also on the latest version
@joulev do you think downgrading to a lower version would work?
Toyger
Are you using typescript? What does your tsconfig.js file look like? also, what are the contents of your public folder (if you have one) ?
I've run into favicon issues if I had a favicon saved in both the public folder and the app folder.
BengalOP
Using Javascript:
Favicon is only in App Dir:
Toyger
What are the exact commands you use to run it? Make sure to run npm install before running it.
BengalOP
npx create-next-app@latest
and i ran npm i aswell
Actually I ran npm I after running npm run dev
Should I try reversing the process?
Toyger
try npm i && npm run dev
BengalOP
Okay, generating a new project, will let you know.
BengalOP
@Toyger the erorr persists,
Toyger
what options did you use when generating the app?
BengalOP
powershell
Toyger
I meant these. I just created one with the following options and it runs without issue.
BengalOP
Kept it to a minimum to reduce build time
Toyger
Is build time really that bif of an issue though?
BengalOP
No
American Crocodile
i'm getting this same error right now as well, my project was being run with npm run dev perfectly then all of a sudden all my routes got these errors from imports at the top for absolutly no reason..
@Toyger Is build time really that bif of an issue though?
BengalOP
Just wanted to test your theory
American Crocodile
hahahaha i get u
but now im kind of freaking out because this is a saas project not just a personal one
@Toyger Is build time really that bif of an issue though?
BengalOP
Please note, the error persists even when I select everything
American Crocodile
idk what's going on and im new to next
Toyger
what if you delete the favicon file?
@American Crocodile idk what's going on and im new to next
BengalOP
I am also new to it, maybe that is the issue.
@Toyger what if you delete the favicon file?
BengalOP
I did that and it gives me google package errors
Toyger
and if you delete .next and the favicon file?
@Bengal I did that and it gives me google package errors
BengalOP
@Toyger and if you delete .next and the favicon file?
BengalOP
Let me try
@Toyger and if you delete .next and the favicon file?
American Crocodile
nothing happened
@American Crocodile nothing happened
You got this error all of a sudden
BengalOP
Yes
Actually no
American Crocodile
yeah
i got it all of a sudden
BengalOP
This happened after upgrading to the latest node js version
I ran a deprecated version of node js before
American Crocodile
this is what i see now after deleting favicon and .next/
maybe that unexpectedend of json means something
@American Crocodile this is what i see now after deleting favicon and .next/
BengalOP
Very different from mine
Toyger
What node/npm version are you using?
delete .next and node_modules install packages again and try to start
BengalOP
ok
@Bengal Node js is also on the latest version
BengalOP
@Toyger the version I am running
American Crocodile
i dont think it has to do with the nodejs version
cuz both me and @Bengal are getting the same importing error
so it has to do with import aliases if i had to guess
Toyger
mmm, that could be. Could you send the output of this just in case: **
American Crocodile
Does it happens with node 18?
Toyger
If @Bengal jsut created a brand new app though, then everything should be in order.

@American Crocodile What does your config.js file look like?
BengalOP
@dumbboy delete .next and node_modules install packages again and try to start
American Crocodile
did all that, nothing new happened
BengalOP
After I deleted the file ran "npm i" and "npm run dev" @dumbboy
Toyger
@American Crocodile if you add a / after one of those imports, does it change anything at all?

ie: import App from '@/my/import/path ?
next.config
BengalOP
it wouldn't import previously if i didn't do that
no
im on vanilla js
@Bengal Click to see attachment
It should be redirected to app right? Nevermind
Toyger
yea, I misread the image that was sent earlier. i thought there were no slashes in it. It won't work without the slash is all.
American Crocodile
i'm kind of (very) upset cuz idk what i did to cause all this
i wasted so many hours ugh
BengalOP
I wasted days
American Crocodile
twinniiiing lol
Toyger
Do you have WSL installed?
American Crocodile
no?
idk what that is
BengalOP
yes
Toyger
Windows Subsystem for Linux
BengalOP
I saw that WSL was recommended
Toyger
I personally use it and it works quite nicely. It just gives you a linux environment to work in instead of windows.
American Crocodile
if @Bengal has it and has the exact same issue i am dealing with, then i dont assume that that's what im missing
@American Crocodile you are randomly getting the error out of nowhere?
American Crocodile
yes
i did absolutly nothing
BengalOP
My WSL has been giving me issue, do you think it is related?
American Crocodile
maybe i created a new directory file in my dashboard but that's it
Toyger
I don't know if it will make a big difference, but maybe.

What kind of WSL issue?
@American Crocodile try npx next info
oops
wrong tag
Can't reproduce this, I'm on Mac.
@Bengal try npx next info
BengalOP
@aardani
@American Crocodile maybe i created a new directory file in my dashboard but that's it
Are you getting the error only on this project or any new next project?
American Crocodile
i haven't tried creating a new project
let me do that and see what happens
eh nothing wrong with it
Toyger
What is the output of Get-Host ?
@Toyger I don't know if it will make a big difference, but maybe. What kind of WSL issue?
BengalOP
The error is a popup in the bottom right, I have been ignoring it for the longest time so I can't remember, maybe something about being to old. WSL
Toyger
lol ok that doesn't tell me a lot 😅
BengalOP
Could it be this?npm install next@canary It says it is not the latest version
@Toyger lol ok that doesn't tell me a lot 😅
BengalOP
Sorry man
Toyger
I doubt it. But I don't really know for sure. Can you run Get-Host ? I'd like to know the powershell version
@dumbboy Are you getting the error only on this project or any new next project?
American Crocodile
dummy project works perfectly
what did i do omg
BengalOP
@Toyger
@American Crocodile what did i do omg
BengalOP
Please remember, please
@American Crocodile what did i do omg
Delete package.lock, modules,.next and try to install packages again.
@dumbboy Delete package.lock, modules,.next and try to install packages again.
BengalOP
I did this, error persists
@Bengal Please remember, please
American Crocodile
that's the thing, i did NOTHING at all and when i saved some tailwind changes it just started freaking out
Toyger
Are you using VSCode? Take a look in the botton corner and look at the line endings. My guess is that it makes no difference, but just make sure that they are aligned for any files you edited.
@dumbboy Delete package.lock, modules,.next and try to install packages again.
American Crocodile
so do i delete both of those then npm i again?
Yeah, three
BengalOP
Toyger
Ok, yea that looks fine.
@Toyger Ok, yea that looks fine.
American Crocodile
mine is fine too
looks like i'm going to have to rebuild from scratch :)
(:
BengalOP
I don't know why but I don't think this is a NEXT problem maybe a problem with the dependencies
@American Crocodile looks like i'm going to have to rebuild from scratch :)
You can try it, IG it will take max 30 min
American Crocodile
welp
it is what it is
Toyger
I don't think it's a next problem either.

@Bengal What do your imports look like in page.js and layout.js ?
BengalOP
@dumbboy @Toyger do you think it is because of the c# in my path?
Toyger
you could try a differnt path
BengalOP
Could be ig
Toyger
not sure what windows thinks of that.
BengalOP
Toyger
ok, those are fine.
@Toyger not sure what windows thinks of that.
BengalOP
I have run ASP.NET core proejcts in this dir, so windows should have an issue.
Try to do it on completely different sir like desktop
BengalOP
dir? ok
will try
Yeah
Toyger
Yea, something that is ideally very short. It looks like some of your paths are getting quite long, and windows sometimes complains about paths that are longer than 260 chars
BengalOP
Trying it in this dir
FYI thanks for the help I am enjoying this troubleshooting session.
It is loading longer than usual maybe that is a good thing?
That's completely fine, next 13 dev is slow TBH
Toyger
dev mode can be very slow
prod is way faster
looks like it works?
Yeah
@Bengal You there?
Toyger
@American Crocodile you could try something similar.
American Crocodile
It doesn't look like anybody has ever faced this issue except for me and @Bengal
BengalOP
Yes
American Crocodile
Lmao
BengalOP
I have been googling for the longest time and npm module not found errors are common, just not this one
@dumbboy Still loading
Okay, progress we have a new error.
This is good
Node version is 18 right?
BengalOP
the next file is still there
@dumbboy Node version is 18 right?
BengalOP
Yes
Okay, I will be back in 5 min
American Crocodile
I'm sure this issue has to do with imports and how next interprets how we import at the top of every file but I'm not sure how I can check what type of "way" next checks my import syntax
BengalOP
@American Crocodile try changing you proj file to something with a shorter path, no spaces or symbols
American Crocodile
It's already like that
BengalOP
Hmmm
Toyger
To be honest I'm not positive you guys have the same issue. Was yours also complaining about the favicon, @American Crocodile ?
American Crocodile
I'm complaining about every import in every file
I said that before
@American Crocodile I said that before
BengalOP
@Toyger I have the same issue, imports errors
American Crocodile
Cuz if I change what I'm looking at, like instead of dashboard I try to enter (settings) in the url there's also gonna be an import error there
Toyger
@Bengal could you stop the other version you have running and restart the new one, then open http://localhost:3000 ?
Is there any chance it's related to this: https://nextjs.org/docs/messages/invalid-project-dir-casing
Totally unrelated, can you try opening it in http://127.0.0.1:3000 instead of locahost
Toyger
Good call. This thread might not be helpful but perhaps it could provide some insight: https://github.com/vercel/next.js/discussions/33299
BengalOP
@Toyger restarted vs code and got the WSL error
That's not error
Toyger
If all else fails, I wold strongly recommend trying it in WSL.

@Bengal ok I see. That's just a warning.
But, it means you have WSL installed.
if you run wsl from powershell then you'll have a wsl console
BengalOP
Yup
Toyger
and you could try from there.
You will need to re-create the project, but it might help.
American Crocodile
OMG GUYS
I think I found the solution
so basically
BengalOP
Please share
American Crocodile
i tried changing the import alias from @/component/url/here to ../component/url/here and it worked
so as i said before
it's with the import alias in jsconfig.js
@American Crocodile i tried changing the import alias from @/component/url/here to ../component/url/here and it worked
So, issue with path alias, can you mention where your component folder is?
American Crocodile
but it should be good idk why it's not working
this is my file structure
looks good
American Crocodile
yes
now
BengalOP
Wait i don't understand
American Crocodile
why is jsconfig not working
BengalOP
can you paste the jsconfig.json file.
Toyger
Wait, are you using a src directory now? You weren't before.
American Crocodile
what should i do cuz i'm not about to change 200 imports from @/ to ../ lmao
BengalOP
It works
Why
Toyger
You could also specify baseUrl: "." which might help @American Crocodile
@Bengal is that in wsl?
BengalOP
What is happening @American Crocodile
@Toyger No
WSL failed
@Toyger You could also specify `baseUrl: "."` which might help <@431780891023507456>
American Crocodile
what's the difference between baseUrl and "Paths"
BengalOP
I need to set it up first
Toyger
ok gotcha. Paths will specify paths relative to the baseUrl
@Toyger <@914734180938682389> is that in wsl?
BengalOP
I love Linux, so will definetly do this
BengalOP
Okay, so when I create a new next js proj, I will have to manually config this?
American Crocodile
Ok so now I'm sure that my issue is "why is next not recognizing the @\ import alias
And I'm sure cuz previously when I used to write @\ it would autocomplete and open a dialogue of my possible imports from that file
I don't think the baseUrl is the issue, I have created new project with the same jsconfig.json file, I have no issues.
American Crocodile
Where does next import the jsconfig file and read it? @dumbboy
TBH IDK too, it's internal stuff
American Crocodile
Can u show me ur tsconfig@dumbboy
American Crocodile
Looks exactly like mine
Yes
BengalOP
So what is wrong with
sorry
why is it referencing src/*
is it because I chose the src option during create?
Yeah
American Crocodile
Because ur using the src directory
BengalOP
So basically it is src or app?
not both
both
just organizing all code related folders inside src. like components, lib,utils instead of keeping it in root directory.
BengalOP
Thanks everyone
Toyger
BaseUrl will just tell your config.js what you mean by . in the paths. It gives it a reference. You don't have to use it though. It looks like everything is working then?
BengalOP
The component file, should it be in src or app?
BengalOP
okay
Toyger
Ahh. I don't think that everything should be inside src. Just the app and components folder. The config files should be outside it.
Toyger
American Crocodile
Toyger
like that
American Crocodile
I may have found a solution on GitHub I'll tell you if it works
BengalOP
Did it work @American Crocodile ?
American Crocodile
im trying to find how to do what they said
Can you send me the issue link
American Crocodile
1 sec
This is the exact same issue I had
It's jest issue, not next
American Crocodile
I know but the same import alias issue should be similar no?
IG no, it's working for him in dev server, just jest is the issue
American Crocodile
So now what... How do I fix my import aliases
Like it's not reading that it should be @\
Can you send any page import code of your files
@American Crocodile this is what i see now after deleting favicon and .next/
American Crocodile
This image shows the imports at the top of the file where it can't read them for some reason
like this for example
it doesnt know what Themeprovider is
@/ is not working?
American Crocodile
yes
when i changed it to /../..componentxx it works
can you show your project structure
American Crocodile
you have to understand, my project structure is fine, my project was working perfectly earlier today
and before, it opened an options menu for different files after i typed @/ and now it doesnt do that anymore
could that be a vs code issue?
like a linting issue or something
it can be, you have any other editor?
American Crocodile
no
Did you try to create next next project with same config as current project and install necessary packages and just copy paste.
American Crocodile
i dont wanna do that
i did alot of things
for this one
Yeah, I can understand
You sure, you didn't mess with config files, before this issue came.
American Crocodile
nope
i didnt do anything at all
i remember i was modifying some tailwind in my components
okay, weird.
Didn't install any packages, changin node versions?
American Crocodile
no
any vscode.json configs?
@dumbboy any vscode.json configs?
American Crocodile
where do i look?
If you had messed with it, it will be in you root folder.
American Crocodile
no
i hadn't
can you run npm run build and npm run start. Want to check if alias is only issue with dev server or not?
American Crocodile
Ok
Running build rn
If it doesn't work I'll call it a day and just go again from scratch tomorrow
WAIT
It says it can't resolve the alias again
On build
Okay, Sorry to say, but IG you can just create it from scratch and set it up in 1 hour.
American Crocodile
It is what it is haha
Thanks for taking the time tho
Should be frustating, but what can we do.
All the best
American Crocodile
@dumbboy i fixed it lol