PlasmoHQ / plasmo

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

[BUG] pnpm build Failed to resolve #750

Open asyncguo opened 1 year ago

asyncguo commented 1 year ago

What happened?

This prompts when pnpm build, but there is no problem when pnpm dev.

Version

Latest

What OS are you seeing the problem on?

MacOSX

What browsers are you seeing the problem on?

Chrome

Relevant log output

🟣 Plasmo v0.82.5
πŸ”΄ The Browser Extension Framework
πŸ”΅ INFO   | Prepare to bundle the extension...
πŸ”΅ INFO   | Loaded environment variables from: []
πŸ”΄ ERROR  | Failed to resolve '../../../background/index' from './.plasmo/static/background/index.ts'
πŸ”΄ EXIT   | πŸ‘‹ Good bye and have a great day!
 ELIFECYCLE  Command failed with exit code 1.

(OPTIONAL) Contribution

Code of Conduct

ivliag commented 1 year ago

I'm having the same issue with yarn berry.

Zweihander-Main commented 1 year ago

Also have had this problem for a bit but just got to creating a reproduction.

When using the src dir, this happens with either a background/index.ts or background.ts structure. When using the non-src default structure, it seems to only happen when using background/index.ts but works when using background.ts.

plasmo build --verbose:

🟑 0      | Running command: build
🟣 Plasmo v0.83.0
πŸ”΄ The Browser Extension Framework
πŸ”΅ INFO   | Prepare to bundle the extension...
🟑 1      | Creating Manifest Factory...
🟑 2      | Ensure exists: /project/home/zweihander-main/workspace/.plasmo
🟑 3      | Plasmo version file not found, busting cache...
🟑 4      | /project/home/zweihander-main/workspace/assets/icon.png found, creating resized icons
🟑 5      | Creating static templates for popup
🟑 6      | Creating static templates for options
🟑 7      | Creating static templates for newtab
🟑 8      | Creating static templates for devtools
🟑 9      | Creating static templates for sidepanel
🟑 10     | { messageHandlerList: [], portHandlerList: [] }
🟑 11     | Creating BGSW entry
🟑 12     | Hash changed, updating manifest
πŸ”΅ INFO   | Loaded environment variables from: []
🟑 0      | Reinitializing remote cache directory
🟑 0      | @plasmohq/parcel-transformer-manifest
🟑 1      | Adding icons
🟑 2      | Adding default_icon
🟑 3      | Handling background scripts
🟑 4      | Handling background service worker
πŸ”΄ ERROR  | Failed to resolve '../../../background/index' from './.plasmo/static/background/index.ts'
🟑 13     | undefined
πŸ”΄ EXIT   | πŸ‘‹ Good bye and have a great day!

OS: Arch Linux 6.4.12

Zweihander-Main commented 1 year ago

Update: cracked it on my end. On both the repro above and my own project, the package.json had a "main": "index.js" line which when removed, eliminated the problem.

louisgv commented 1 year ago

I think it's either the main field that @Zweihander-Main got (which made the repo a cjs project). The other is that you might need to check and fix the tsconfig path :-?..

Also try cleaning up the .plasmo dir and re-build.

ivliag commented 1 year ago

In my case, the problem was that I had engines.node in my package.json set like this:

  "engines": {
    "node": ">=18"
  }

And there is an issue in parcel-bundler describing this exact problem: https://github.com/parcel-bundler/parcel/issues/7636#issuecomment-1059401129

So I just had to add the target to my package.json, so it works like this:

  "engines": {
    "node": ">=18"
  },
  "targets": {
    "default": {
      "engines": {
        "browsers": "last 2 versions, not dead, > 0.2%"
      }
    }
  }
asyncguo commented 1 year ago

In my case, the problem was that I had engines.node in my package.json set like this:

  "engines": {
    "node": ">=18"
  }

And there is an issue in parcel-bundler describing this exact problem: parcel-bundler/parcel#7636 (comment)

So I just had to add the target to my package.json, so it works like this:

  "engines": {
    "node": ">=18"
  },
  "targets": {
    "default": {
      "engines": {
        "browsers": "last 2 versions, not dead, > 0.2%"
      }
    }
  }

me too

xiaokaike commented 11 months ago

In my case, the problem was that I had engines.node in my package.json set like this:

  "engines": {
    "node": ">=18"
  }

And there is an issue in parcel-bundler describing this exact problem: parcel-bundler/parcel#7636 (comment)

So I just had to add the target to my package.json, so it works like this:

  "engines": {
    "node": ">=18"
  },
  "targets": {
    "default": {
      "engines": {
        "browsers": "last 2 versions, not dead, > 0.2%"
      }
    }
  }

me too, think you very much

lnoss commented 11 months ago

So I am not alone. This issue is closed on Parcel without an explanation... Removing the engines.node key or keeping it while adding browsers definitely work. For whatever it means. This looks like misuses of keys.

jacky1234 commented 6 months ago

remove "engines" config in package.json fixed my issue