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鈥檒l 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 <4586894+mischnic@users.noreply.github.com>
@lettertwo
Copy link
Member

#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