npm run Build Failed

This issue has been tracked since 2022-12-01.

While trying to bundle with parcel, i ran "npm run start" after assigning the "start" and "build" in the scripts inside the package.json but it gave an error with the following message:

Build failed.

@parcel/core: Unexpected output file type .html in target "main"

"description": "Reciepe App",

5 | "main": "index.html",
| ^^^^^^^^^^^^ File extension must be .js, .mjs, or .cjs
6 | "scripts": {
7 | "start": "parcel index.html"

💡 The "main" field is meant for libraries. If you meant to output a .html file, either remove the "main" field or choose a different target

And when i tried removing the main and the index.html. It gives an error that "Browser scripts cannot have imports or exports."

akozdev wrote this answer on 2022-12-01

You should remove this line "main": "index.html", from you package.json file. NPM adds it by default to the package.json file on initial creation, and Parcel uses that "main" field as the output path for libraries (source) which causes an error in this case because Forkify is a standalone project (not a library) with the Html file as an entry point.

To solve this error "Browser scripts cannot have imports or exports.", add type="module" to the <script> tag in the index.html file

<script type="module" src="src/js/controller.js"></script>

This change is needed because modules in [email protected] match the behavior of native modules (non-module files can't have imports and exports) (source).

mister-abdurahman wrote this answer on 2022-12-01

Thanks akozdev, It now works. Thanks for taking your time to explain the details to me. i really appreciate it man. !

Roshanbnair wrote this answer on 2022-12-10

@mister-abdurahman You could deploy the app on the web ?

More Details About Repo
Owner Name jonasschmedtmann
Repo Name complete-javascript-course
Full Name jonasschmedtmann/complete-javascript-course
Language JavaScript
Created Date 2018-06-14
Updated Date 2023-03-29
Star Count 12137
Watcher Count 850
Fork Count 14403
Issue Count 153


Issue Title Created Date Updated Date