Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target "main" declares an output file path of "dist/script.js" which does not match the compiled bundle type "html". #7129

Closed
ezengaston opened this issue Oct 18, 2021 · 8 comments

Comments

@ezengaston
Copy link

🐛 bug report

Parcel doesn't build your files, just throws an Error: @parcel/namer-default: Target "main" declares an output file path of "dist/script.js" which does not match the compiled bundle type "html".

🎛 Configuration (.babelrc, package.json, cli command)

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "dist/script.js",
  "scripts": {
    "start": "parcel src/index.html",
    "build": "parcel build src/index.html"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "parcel": "^2.0.0"
  }
}

🤔 Expected Behavior

Should build your files correctly into dist folder without errors

😯 Current Behavior

Throws an Error: @parcel/namer-default: Target "main" declares an output file path of "dist/script.js" which does not match the
compiled bundle type "html".

    4 |   "description": "",
  > 5 |   "main": "dist/script.js",
  >   |           ^^^^^^^^^^^^^^^^ Did you mean "dist/script.html"?
    6 |   "scripts": {
    7 |     "start": "parcel src/index.html",

If I change main to "dist/script.html" and run build, then it asks again to change file format back to .js

💁 Possible Solution

🔦 Context

💻 Code Sample

HTML file:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="./script.js" type="module"></script>
    <title>Document</title>
</head>
<body>
    <div>Hello</div>
</body>
</html>

JaveScript file:
console.log("hi");

🌍 Your Environment

Software Version(s)
Parcel 2.0.0
Node 14.15.5
npm/Yarn 6.14.11
Operating System macOS Big Sur 11.6
@mischnic
Copy link
Member

Is there a reason you specified "main": "dist/script.js",? Can you just remove it? https://parceljs.org/getting-started/migration/#package.json%23main

@ezengaston
Copy link
Author

Thank you!!

@KaKi87
Copy link

KaKi87 commented Feb 8, 2022

Hello,
As I'm trying to programmatically build an Electron app, electron-builder requires the main field in package.json to point to the Electron app's main file.
Thanks

@DDowl51
Copy link

DDowl51 commented Jul 5, 2022

Hello, As I'm trying to programmatically build an Electron app, electron-builder requires the main field in package.json to point to the Electron app's main file. Thanks

If you do need to keep the main field, and want Parcel to ignore it, you can add "targets": { "main": false } to your package.json. See Library targets for details.

@KaKi87
Copy link

KaKi87 commented Jul 7, 2022

Would it be possible to do this only by changing options in await new Parcel(options).run() ?
Thanks !

@CodeWithAlamin
Copy link

Is there a reason you specified "main": "dist/script.js",? Can you just remove it? https://parceljs.org/getting-started/migration/#package.json%23main

Thanks! It solves the issue.

@aimagist
Copy link

Thanks, this works perfectly.

Is there a reason you specified "main": "dist/script.js",? Can you just remove it? https://parceljs.org/getting-started/migration/#package.json%23main

@Qeebx
Copy link

Qeebx commented Nov 4, 2023

Thank you. This was very helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants