Reputation: 179
Installed node, ran npm init to create package.json, installed parcel. running the server with npx parcel index.html runs the server. Then I changed "scripts" to "start": "parcel index.html" in package.json, and run npm run start, it also runs the server without a problem. And then I added to "scripts" "build": "parcel build index.html" and run npm run build. But this does not work... I get the error below...
> [email protected] build
> parcel build index.html
× Build failed.
@parcel/namer-default: Target "main" declares an output file path of "index.js" which does not match the compiled bundle type "html".
C:\Users\ijevr\Desktop\JavaScript\vjezba 17\package.json:4:11
3 | "version": "1.0.0",
> 4 | "main": "index.js",
> | ^^^^^^^^^^ Did you mean "index.html"?
5 | "scripts": {
6 | "start": "parcel index.html",
ℹ Try changing the file extension of "main" in package.json.
Of course, changing the main to index.html states that the file should be a .js file... index.js is what the npm init created in the package.json. In my folder, my main js file is named script.js, and it was named like this before I ran npm init. However changing the main to script.js also does not help, I get the same error as stated here...
I don't know what to do to npm build it...
Upvotes: 5
Views: 5418
Reputation: 11
The structure of the package.json file should look like this when using the Parcel library
"targets": {
"main": false
},
"scripts": {
"start": "parcel index.html",
"build": "parcel build index.html"
}
Upvotes: 1
Reputation: 441
To resolve these issues. Kindly remove the "main": "index.js",
from the package.json files.
From this package.json::
{
"main": "index.js",
"scripts": {
"start": "parcel index.html",
"build": "parcel build index.html"
}
}
To this package.json::
{
"scripts": {
"start": "parcel index.html",
"build": "parcel build index.html"
}
}
https://parceljs.org/getting-started/migration/#package.json%23main
Upvotes: 4
Reputation: 1
For me, this worked https://stackoverflow.com/a/71708198/20383654
I added the following as suggested and the build worked.
"targets": { "main":false },
Upvotes: 0
Reputation: 31
Remove the main
property from package.json
completely, or add this to the package.json
:
"targets": {
"main": false
},
Upvotes: 3
Reputation: 179
I didn't find a fix, but I found out that with Parcel 2 the build process changed. Works now.
Script should look like this:
"start": "parcel",
"build": "parcel build"
and main and source like this:
"main": "dist/index.js", //with dist being the path of the build
"source": "src/script.js", //and src the path of our project
Upvotes: 2