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 adds hmr-runtime to { context: node } #10030

Open
tony-g opened this issue Dec 4, 2024 · 2 comments
Open

Parcel adds hmr-runtime to { context: node } #10030

tony-g opened this issue Dec 4, 2024 · 2 comments

Comments

@tony-g
Copy link

tony-g commented Dec 4, 2024

🐛 bug report

In a project with both web and node targets, Parcel adds the hmr-runtime to both web and node targets.

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

🤔 Expected Behavior

Parcel doesn't add hmr-runtime to node targets

😯 Current Behavior

Parcel adds the hmr-runtime to node targets

💁 Possible Solution

  • I copy/pasted hmr-runtime and added bundle.env.context === 'node' to the short-circuit condition.
  • So far, this seems to fix it, but not sure if they are unintended side-effects, or why it might not have been included originally.
    if (
      bundle.type !== 'js' ||
      !options.hmrOptions ||
      bundle.env.isLibrary ||
      bundle.env.isWorklet() ||
      bundle.env.sourceType === 'script' ||
      bundle.env.context === 'node' // (?) add this (?)
    ) {
      return
    }

🔦 Context

I'm trying to build a webapp and serverless functions in the same project so there are node and web targets. (Prebuilding the node targets makes them more easily portable across serverless providers.)

💻 Code Sample

https://github.com/tony-g/parcel-hmr-node/

🌍 Your Environment

Software Version(s)
Parcel 2.13.2
Node 18.17.1
npm/Yarn yarn 1.22
Operating System MacOS
@devongovett
Copy link
Member

This will actually be supported in node shortly due to some other work. In the meantime you can run Parcel with the --no-hmr flag.

@tony-g
Copy link
Author

tony-g commented Dec 11, 2024

Great, thanks!

Not important, because the hmr-runtime tweak seems to work, but - Am I not supposed to be building web and node targets with the same parcel instance?

The reason I ask is that running with the --no-hmr flag has a problem with my particular situation because it turns off hmr for both the node and web targets, so unlike the hmr-runtime tweak, it appears to lose hmr completely, not just for the node targets.

// webapp/package.json
// still want hmr here
 "targets": {
    "app": {
      "context": "browser",
      "distDir": "dist",
      "source": "src/index.html",
      "scopeHoist": false
    }
  },
// api/package.json
// don't want hmr
  "fn1": {
    "gcp": {
      "context": "node",
      "optimize": false,
      "outputFormat": "commonjs",
      "scopeHoist": false,
      "source": "server/apps/api/app.generated.ts",
      "sourceMap": false
    },
    "fn2": {
      "context": "node",
      "optimize": false,
      "outputFormat": "commonjs",
      "scopeHoist": false,
      "source": "server/apps/examplify/app.generated.ts",
      "sourceMap": false
    },
   ...
  },
// my parcel wrapper
const parcel = new Parcel({
    ...
    entries: ['packages/webapp', 'packages/api'],
    mode: 'development',
    hmrOptions: { port: 2346 },
    serveOptions: false // everything except hmr is served by firebase-tools
  })

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