I am building a server side rendered website after i built the api for it.
Now, I am getting this error cannot find module 'axios'
when importing axios in a js module and bundling it using parcel 2.0.1.
Parcel and axios are both installed as dependencies and axios is installed as a dev dependency as well, and it is in the node modules.
Before I installed parcel and when I imported the js file into the html pug file, axios worked fine (it did the fetching as expected), but only when I tried to bundle it that it started giving me this error.
Any help is appreciated, thank you.
CodePudding user response:
In the closest (from the root of project directory) package.json file, add or update "type" field with a value of "module". It will ensure that all your .js, .ts and .mjs files are interpreted as ES modules.
...
{
...
"type": "module"
...
}
...
CodePudding user response:
axios should install as dependencies, not dev dependency.please try it.