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

Bug Report: parcel watch errors when building a react library #7652

Closed
e-krebs opened this issue Feb 4, 2022 · 4 comments
Closed

Bug Report: parcel watch errors when building a react library #7652

e-krebs opened this issue Feb 4, 2022 · 4 comments

Comments

@e-krebs
Copy link

e-krebs commented Feb 4, 2022

🐛 bug report

when building a library that contains react component, parcel works with the build command line, but watch outputs an error:

@parcel/packager-js: Asset was skipped or not found.
AssertionError [ERR_ASSERTION]: Asset was skipped or not found.
at ScopeHoistingPackager.getSymbolResolution
...

also reported here: #7495

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

no babel config when the bug happens.

Full repro described here: https://github.com/e-krebs/parcel-react-library

important parts of the package.json looks like:

{
// ...
  "source": "src/index.ts",
  "main": "dist/index.js",
  "types": "dist/types.d.ts",
  "targets": {
    "main": {
      "isLibrary": true,
      "context": "browser"
    }
  },
  "scripts": {
    "build": "parcel build",
    "watch": "parcel watch",
  },
  "devDependencies": {
    "@parcel/packager-ts": "^2.2.1",
    "@parcel/transformer-typescript-types": "^2.2.1",
    "@types/express": "^4.17.13",
    "@types/react": "^17.0.39",
    "@types/react-dom": "^17.0.11",
    "parcel": "^2.2.1",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "typescript": "^4.5.5"
  },
  "peerDependencies": {
    "react": "^17.0.2",
    "react-dom": "^17.0.2"
  },
  "alias": {
    "@parcel/transformer-react-refresh-wrap": "./node_modules/@parcel/transformer-react-refresh-wrap"
  }
}

and then, the src/index.ts file exports a React component from another file.

🤔 Expected Behavior

parcel watch should not output an error but work (same as parcel build works, actually).

😯 Current Behavior

parcel watch outputs an error (error message on Windows below, but the same happen on linux):

yarn : @parcel/packager-js: Asset was skipped or not found.
At line:1 char:1
+ yarn watch
+ ~~~~~~~~~~

  AssertionError [ERR_ASSERTION]: Asset was skipped or not found.
  at ScopeHoistingPackager.getSymbolResolution
  (C:\projects\parcel-react-library\node_modules\@parcel\packager-js\lib\ScopeHoistingPackager.js:732:29)
  at C:\projects\parcel-react-library\node_modules\@parcel\packager-js\lib\ScopeHoistingPackager.js:836:31
  at Array.map (<anonymous>)
  at ScopeHoistingPackager.buildAssetPrelude
  (C:\projects\parcel-react-library\node_modules\@parcel\packager-js\lib\ScopeHoistingPackager.js:835:37)
  at ScopeHoistingPackager.buildAsset
  (C:\projects\parcel-react-library\node_modules\@parcel\packager-js\lib\ScopeHoistingPackager.js:398:48)
  at ScopeHoistingPackager.visitAsset
  (C:\projects\parcel-react-library\node_modules\@parcel\packager-js\lib\ScopeHoistingPackager.js:357:17)
  at C:\projects\parcel-react-library\node_modules\@parcel\packager-js\lib\ScopeHoistingPackager.js:456:56
  at String.replace (<anonymous>)
  at ScopeHoistingPackager.buildAsset
  (C:\projects\parcel-react-library\node_modules\@parcel\packager-js\lib\ScopeHoistingPackager.js:420:19)
  at ScopeHoistingPackager.visitAsset
  (C:\projects\parcel-react-library\node_modules\@parcel\packager-js\lib\ScopeHoistingPackager.js:357:17)

💁 Possible Solution

a workaround is to use babel (see Code Sample below), but:

  • parcel outputs warning when doing so
  • it is slower
  • it produces a larger bundle

🔦 Context

Just building a library that contains react components. It is for internal use, but it could be a public design system library for example.

💻 Code Sample

https://github.com/e-krebs/parcel-react-library

🌍 Your Environment

Software Version(s)
Parcel 2.2.1
Node 16.13.0
npm/Yarn 1.22.5
Operating System Windows 10 / Ubuntu in wsl
lettertwo added a commit that referenced this issue Apr 6, 2022
For library targets:
  - Skips applying refresh transforms in JSTransformer
  - Skips applying ReactRefreshRuntime
  - Skips applying transforms in ReactRefreshWrapTransformer
  - Adds test asserting that runtime and transforms are not applied

Fixes #7359, #7496, #7652, #7900
See also: #6892
devongovett pushed a commit that referenced this issue Apr 7, 2022
For library targets:
  - Skips applying refresh transforms in JSTransformer
  - Skips applying ReactRefreshRuntime
  - Skips applying transforms in ReactRefreshWrapTransformer
  - Adds test asserting that runtime and transforms are not applied

Fixes #7359, #7496, #7652, #7900
See also: #6892

Co-authored-by: Niklas Mischkulnig <[email protected]>
@lettertwo
Copy link
Contributor

#7914 should resolve this.

@e-krebs
Copy link
Author

e-krebs commented Apr 8, 2022

#7914 should resolve this.

@lettertwo is there a way to reference this version of parcel without waiting for a release?
I'm not sure how to do that since this is a monorepo :/

@mischnic
Copy link
Member

mischnic commented Apr 8, 2022

@e-krebs Yes, use yarn add parcel@nightly

@e-krebs
Copy link
Author

e-krebs commented Apr 8, 2022

@mischnic perfect, it works 🙂
Thx for the work on this one, I'll wait for the next release!

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

3 participants