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

Parcel output empty js files #9197

Closed
MoonLGH opened this issue Aug 16, 2023 · 5 comments
Closed

Parcel output empty js files #9197

MoonLGH opened this issue Aug 16, 2023 · 5 comments

Comments

@MoonLGH
Copy link

MoonLGH commented Aug 16, 2023

🐛 bug report

Simmilar to #7646
parcel build src/*.html returns empty javascript with a comment point to a source file, example is on https://github.com/RPLSaci/MyPadi
the main branch has a not empty login.js on the assets/js

but look at the gh-pages branch, the login.js in empty but not the index.js, index.js file is not empty

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

{
  "name": "tcunim",
  "license": "MIT",
  "scripts": {
    "dev": "parcel src/*.html",
    "build": "parcel build src/*.html",
    "buildNotRoot": "parcel build --public-url '/MyPadi' src/*.html"
  },
  "dependencies": {
    "autoprefixer": "^10.4.7",
    "daisyui": "^2.15.1",
    "flowbite": "^1.5.1",
    "parcel": "^2.6.0",
    "postcss": "^8.4.14",
    "postcss-purgecss": "^2.0.3",
    "tailwindcss": "^3.0.24"
  }
}

🤔 Expected Behavior

Export a non empty js file

😯 Current Behavior

Export an empty js file

💁 Possible Solution

  • i dont know

🔦 Context

This bug really affects my ci/cd since my project automaticly puts the gh pages by the github workflows

💻 Code Sample

🌍 Your Environment

Software Version(s)
Parcel 2.9.3^(on local)
Node 18.16.1^
npm/Yarn 9.5.1
Operating System Tried on Debian, ubuntu, windows 10
@jondlm
Copy link
Contributor

jondlm commented Aug 24, 2023

Looks like your login.js file is probably getting dead code eliminated since it's not actually doing anything. Try adding a console.log() to the file to have it stick around.

@MoonLGH
Copy link
Author

MoonLGH commented Aug 25, 2023

image

ITS NOW ONLY EXPORTING THE CONSOL LOG AHAHAHAHA

@jondlm
Copy link
Contributor

jondlm commented Aug 25, 2023

Try adding "sideEffects": true in your package.json. I think your project is setup a bid oddly. Usually you'd have one entrypoint JS file per page that did something instead of just defining a bunch of unused functions. Either way I think that flag should help.

@jondlm
Copy link
Contributor

jondlm commented Aug 25, 2023

Okay, dug a little more into this one cause it intersected with some of my own work. Looks like Parcel shouldn't really be dead code eliminating your code since your <script> tag doesn't have the type="module" type therefore it's a classic script. So that's unexpected.

I tried playing around with adding an .swcrc file with:

{
  "isModule": false,
  "jsc": {
    "minify": {
      "compress": {
        "unused": false,
        "mange": false
      }
    }
  }
}

But that didn't work.

At the moment the only workaround I found was adding --no-optimize to the parcel build command which isn't ideal but it works.

@MoonLGH
Copy link
Author

MoonLGH commented Aug 26, 2023

image
definitely --no-optimze works, i guess ill use it for now

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

2 participants