PlasmoHQ / plasmo

🧩 The Browser Extension Framework
https://www.plasmo.com
MIT License
10.39k stars 362 forks source link

[BUG] pnpm dev error #733

Open ailikecreative opened 1 year ago

ailikecreative commented 1 year ago

What happened?

pnpm dev command always has problems,I've tried repeatedly still fails I tried to install the manual '@parcel/diagnostic' but it still got an error

Version

Latest

What OS are you seeing the problem on?

Windows

What browsers are you seeing the problem on?

Chrome, Microsoft Edge

Relevant log output

🟣 Plasmo v0.82.1
🔴 The Browser Extension Framework
🔵 INFO   | Starting the extension development server...
🔵 INFO   | Loaded environment variables from: []
node:internal/event_target:1012
  process.nextTick(() => { throw err; });
                           ^

Error: Cannot find module '@parcel/diagnostic'
Require stack:
- C:\Users\Edi\Desktop\New-Develop-Web\plasmo-extension-framework\multi-tools\node_modules\.pnpm\@parcel+logger@2.9.3\node_modules\@parcel\logger\lib\Logger.js
- C:\Users\Edi\Desktop\New-Develop-Web\plasmo-extension-framework\multi-tools\node_modules\.pnpm\@parcel+utils@2.9.3\node_modules\@parcel\utils\lib\index.js
- C:\Users\Edi\Desktop\New-Develop-Web\plasmo-extension-framework\multi-tools\node_modules\.pnpm\@parcel+core@2.9.3\node_modules\@parcel\core\lib\public\Config.js
- C:\Users\Edi\Desktop\New-Develop-Web\plasmo-extension-framework\multi-tools\node_modules\.pnpm\@parcel+core@2.9.3\node_modules\@parcel\core\lib\utils.js
- C:\Users\Edi\Desktop\New-Develop-Web\plasmo-extension-framework\multi-tools\node_modules\.pnpm\@parcel+core@2.9.3\node_modules\@parcel\core\lib\public\Environment.js
- C:\Users\Edi\Desktop\New-Develop-Web\plasmo-extension-framework\multi-tools\node_modules\.pnpm\@parcel+core@2.9.3\node_modules\@parcel\core\lib\public\Asset.js
- C:\Users\Edi\Desktop\New-Develop-Web\plasmo-extension-framework\multi-tools\node_modules\.pnpm\@parcel+core@2.9.3\node_modules\@parcel\core\lib\Parcel.js
- C:\Users\Edi\Desktop\New-Develop-Web\plasmo-extension-framework\multi-tools\node_modules\.pnpm\@parcel+core@2.9.3\node_modules\@parcel\core\lib\index.js
- C:\Users\Edi\Desktop\New-Develop-Web\plasmo-extension-framework\multi-tools\node_modules\.pnpm\@parcel+fs@2.9.3_@parcel+core@2.9.3\node_modules\@parcel\fs\lib\index.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
    at Module._load (node:internal/modules/cjs/loader:920:27)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at _diagnostic (C:\Users\Edi\Desktop\New-Develop-Web\plasmo-extension-framework\multi-tools\node_modules\.pnpm\@parcel+logger@2.9.3\node_modules\@parcel\logger\lib\Logger.js:24:16)
    at Logger.error (C:\Users\Edi\Desktop\New-Develop-Web\plasmo-extension-framework\multi-tools\node_modules\.pnpm\@parcel+logger@2.9.3\node_modules\@parcel\logger\lib\Logger.js:60:26)
    at WorkerFarm.onError (C:\Users\Edi\Desktop\New-Develop-Web\plasmo-extension-framework\multi-tools\node_modules\.pnpm\@parcel+workers@2.9.3_@parcel+core@2.9.3\node_modules\@parcel\workers\lib\WorkerFarm.js:205:25)
    at Worker.<anonymous> (C:\Users\Edi\Desktop\New-Develop-Web\plasmo-extension-framework\multi-tools\node_modules\.pnpm\@parcel+workers@2.9.3_@parcel+core@2.9.3\node_modules\@parcel\workers\lib\WorkerFarm.js:220:36)
    at Worker.emit (node:events:513:28)
    at worker.WorkerBackend.exitCode (C:\Users\Edi\Desktop\New-Develop-Web\plasmo-extension-framework\multi-tools\node_modules\.pnpm\@parcel+workers@2.9.3_@parcel+core@2.9.3\node_modules\@parcel\workers\lib\Worker.js:79:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Users\\Edi\\Desktop\\New-Develop-Web\\plasmo-extension-framework\\multi-tools\\node_modules\\.pnpm\\@parcel+logger@2.9.3\\node_modules\\@parcel\\logger\\lib\\Logger.js',
    'C:\\Users\\Edi\\Desktop\\New-Develop-Web\\plasmo-extension-framework\\multi-tools\\node_modules\\.pnpm\\@parcel+utils@2.9.3\\node_modules\\@parcel\\utils\\lib\\index.js',
    'C:\\Users\\Edi\\Desktop\\New-Develop-Web\\plasmo-extension-framework\\multi-tools\\node_modules\\.pnpm\\@parcel+core@2.9.3\\node_modules\\@parcel\\core\\lib\\public\\Config.js',
    'C:\\Users\\Edi\\Desktop\\New-Develop-Web\\plasmo-extension-framework\\multi-tools\\node_modules\\.pnpm\\@parcel+core@2.9.3\\node_modules\\@parcel\\core\\lib\\utils.js',
    'C:\\Users\\Edi\\Desktop\\New-Develop-Web\\plasmo-extension-framework\\multi-tools\\node_modules\\.pnpm\\@parcel+core@2.9.3\\node_modules\\@parcel\\core\\lib\\public\\Environment.js',
    'C:\\Users\\Edi\\Desktop\\New-Develop-Web\\plasmo-extension-framework\\multi-tools\\node_modules\\.pnpm\\@parcel+core@2.9.3\\node_modules\\@parcel\\core\\lib\\public\\Asset.js', 
    'C:\\Users\\Edi\\Desktop\\New-Develop-Web\\plasmo-extension-framework\\multi-tools\\node_modules\\.pnpm\\@parcel+core@2.9.3\\node_modules\\@parcel\\core\\lib\\Parcel.js',        
    'C:\\Users\\Edi\\Desktop\\New-Develop-Web\\plasmo-extension-framework\\multi-tools\\node_modules\\.pnpm\\@parcel+core@2.9.3\\node_modules\\@parcel\\core\\lib\\index.js',
    'C:\\Users\\Edi\\Desktop\\New-Develop-Web\\plasmo-extension-framework\\multi-tools\\node_modules\\.pnpm\\@parcel+fs@2.9.3_@parcel+core@2.9.3\\node_modules\\@parcel\\fs\\lib\\index.js'
  ]
}

Node.js v18.16.0
 ELIFECYCLE  Command failed with exit code 1

(OPTIONAL) Contribution

Code of Conduct

louisgv commented 1 year ago

@ailikecreative I think this should be addressed by upstream Parcel rather than Plasmo - since the stacktrace points to parcel-core. I'm not entirely sure how your project couldn't run - are you mix-matching your node/pnpm installation somehow between WSL and PWSH?... (this error and #734 potentially) might share the same cause within your system, unless you can share a clean reprod

ailikecreative commented 1 year ago

in the contents folder, if I only put 1 file there the code runs normally, but if I put lots of sample files in my case there are 15 for each different website, when "pnpm dev" an error like that appears.

so according to the assumption that the cause is because there are too many files in the content folder, I don't know if this is true or not

tj-noor commented 1 year ago

I have been running into this issue (with pnpm & windows) since I tried adding a background message handler. Right now, the only way I can get a dev build is on a Mac instead. Not sure if it's related to the libraries I have imported, but I'll try and see if I can get a repro on a new project on that windows machine.

Update: this isn't related to the background script directly - just additional files. It appears that there isn't much tree-shaking, if at all, being done on some imports like lucide-react, zod, etc. I also had react-router on a tabs entry point with multiple pages being imported lazily. That spun out separate files in the root directory with duplicated/shared bundles. My parcel cache data.mdb file was at 4gb.

After porting the extension over to work with parcel natively, build times have improved considerably and the cache data.mdb file is now sitting at under 50mb. It also seems to reuse the shared bundles more efficiently, but tree-shaking is similar since the underlying imports use conditional requires.

I came across the recommendation/work-around of increasing the minBundles like plasmo has configured due to an open issue with parcel (https://github.com/parcel-bundler/parcel/issues/8071), and updating the following configuration resulted in similar bundle file sizes like plasmo, but still the smaller cache file size.

  "@parcel/bundler-default": {
    "minBundles": 10000000,
    "minBundleSize": 3000,
    "maxParallelRequests": 20
  }

In conclusion, I'll have to keep a closer eye on the imported packages as this could easily get out of hand.