I have a monorepo with two packages. One is the library that exports a Deck.gl Layer and the other is a demo for displaying that library in a browser.
Here is the library package.json:
{
"name": "@myorg/the-library"
"version": "0.0.0",
"private": true,
"description": "The library package",
"license": "UNLICENSED",
"type": "module",
"main": "dist/index.js",
"types": "index.d.ts",
"scripts": {
"build": "parcel build ./src/index.ts",
"dev": "parcel watch ./src/index.ts --port 4444"
},
"dependencies": {
"deck.gl": "^8.3.0",
"memoize-one": "^5.1.1"
},
"devDependencies": {
"@danmarshall/deckgl-typings": "^4.5.1",
"parcel": "^2.0.0-beta.1",
"typescript": "^4.1.3"
},
"externals": {
"@deck.gl/core": "deck.gl",
"@deck.gl/layers": "deck.gl"
},
"targets": {
"types": false
}
}
And here is the demo package.json:
{
"name": "@myorg/demo",
"version": "0.0.0",
"private": true,
"description": "Demo Application",
"license": "UNLICENSED",
"scripts": {
"dev": "parcel serve src/index.html"
},
"browserslist": "> 0.2%%",
"dependencies": {
"@myorg/the-library": "*",
"deck.gl": "^8.3.0",
"parcel": "^2.0.0-beta.1",
"react": "^17.0.1",
"react-dom": "^17.0.1"
},
"devDependencies": {
"@danmarshall/deckgl-typings": "^4.5.1",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"typescript": "^4.1.3"
}
}
I am able to build the library and then run the demo like this:
yarn workspace @myorg/the-library build
yarn workspace @myorg/demo dev
This works!
But, if I make a change the library code, I need to manually rebuild it to trigger the demo to update.
So, to automate those updates, I am running these commands in parallel (in the monorepo root, or just manually in two terminals for the time-being):
yarn workspace @myorg//the-library dev
yarn workspace @myorg/demo dev
🤔 Expected Behavior
I expect that parcel watch
will work just as parcel build
does, and the resulting files will be able to find the dependencies.
😯 Current Behavior
index.c065dc87.js:1198 Uncaught Error: Cannot find module '@deck.gl/core'
at newRequire (index.c065dc87.js:1198)
at newRequire (index.c065dc87.js:1185)
at localRequire (index.c065dc87.js:1209)
at Object.5Y3EG.../shapes (basecall-layer.ts:1)
at newRequire (index.c065dc87.js:1205)
at localRequire (index.c065dc87.js:1209)
at Object.4s2q6../layers/basecall-layer (index.ts:1)
at newRequire (index.c065dc87.js:1205)
at index.c065dc87.js:1237
at Object.eviav (index.c065dc87.js:1254)
and going through the trace shows that the failed import happens inside the-library
.
This does not happen when I build with parcel build
💁 Possible Solution
Manually do yarn workspace @myorg/the-library build
after every change.
🔦 Context
Would like to be able to do hot-reloading on a module that is part of a monorepo
💻 Code Sample
The above package.json files should be enough, I think.
🌍 Your Environment
Software | Version(s) |
---|---|
Parcel | 2.0.0-nightly.560+36de59e1 |
Node | v12.20.1 |
npm/Yarn | yarn |
Operating System | 10.15.7 |
If you add
"source": "src/index.ts"
to the library package.json, the library’s sources will be used directly when running the demo (so it should be watched as you’d expect here). (This is how monorepos are designed to work with Parcel)Not sure about the other error message, that might go away with
source
…