parcel-bundler / parcel

The zero configuration build tool for the web. 📦🚀
https://parceljs.org
MIT License
43.5k stars 2.27k forks source link

Parcel serve fails when target is "electron-renderer" and nodeIntegration is false #4825

Open vazra opened 4 years ago

vazra commented 4 years ago

🐛 bug report

Parcel serve fails when target is "electron-renderer" and nodeIntegration is false

The issue is reproducible at https://github.com/moctrash/parcel2-react-refresh, by changing nodeIntegration to false at https://github.com/moctrash/parcel2-react-refresh/blob/a79aeeab145b89f012cf06ad9e7f0f925bc2b0bb/src/main.js#L16

Screenshot 2020-06-30 at 11 58 42 PM
Uncaught Error: Cannot find module 'react-refresh/runtime'
    at newRequire (parcel2-react-refresh.87ae4380.js:58)
    at newRequire (parcel2-react-refresh.87ae4380.js:42)
    at localRequire (parcel2-react-refresh.87ae4380.js:80)
    at Object.b4a443c708891a61a6c52b4072510451 (helpers.js:3)
    at newRequire (parcel2-react-refresh.87ae4380.js:68)
    at localRequire (parcel2-react-refresh.87ae4380.js:80)
    at Object.4bbd9410408ee35eee2aa9375b49e901../ChildComponent (parcel2-react-refresh.87ae4380.js:137)
    at newRequire (parcel2-react-refresh.87ae4380.js:68)
    at parcel2-react-refresh.87ae4380.js:111
    at parcel2-react-refresh.87ae4380.js:134

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

package.json - https://github.com/moctrash/parcel2-react-refresh/blob/master/package.json

{
  ...
  "main": "src/main.js",
  "scripts": {
    "build": "rimraf .parcel-cache && parcel build src/index.html",
    "start": "rimraf .parcel-cache && parcel src/index.html  -p 3000 --target=react-renderer & yarn open-electron",
    "open-electron": "wait-on http://localhost:3000 && electron ."
  },
  "devDependencies": {
    "parcel": "^2.0.0-beta-1",
    "electron": "^9.0.5",
    ...
  },
  "targets": {
    "react-renderer": {
      "context": "electron-renderer"
    }
  },
  "dependencies": {
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
   ...
  }
}

🤔 Expected Behavior

electron-renderer should be usable irrespective of nodeIntegration

😯 Current Behavior

unable to use electron-renderer when nodeIntegration is false

💻 Code Sample

https://github.com/moctrash/parcel2-react-refresh

🌍 Your Environment

Software Version(s)
Parcel 2.0.0-beta-1
Node v12.16.3
Yarn v1.22.4
Operating System Mac
maximilianschmitt commented 2 years ago

I'm having the same issue (https://github.com/parcel-bundler/parcel/issues/7373). Have you found any fixes or workarounds @vazra ?