Parcel has a runtime dependency on babel-types, but this dependency is not declared in parcel's package.json. With certain workflows (I am using Rush with PNPM), this causes parcel build to fail at runtime.
The config below is for my real-world project. For a minimal repro, see https://github.com/mpiroc/rush-repro.
I do not have a .babelrc.
Root of monorepo:
{
"name": "my-package-name",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "rush build",
"test": "rush test"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {},
"dependencies": {}
}
Specific package:
{
"name": "@mpiroc/my-package",
"version": "0.0.0",
"description": "> TODO: description",
"author": "Matthew Pirocchi <[email protected]>",
"homepage": "https://github.com/mpiroc/my-repo#readme",
"license": "ISC",
"main": "lib/index.ts",
"directories": {
"lib": "lib",
"test": "__tests__"
},
"files": [
"lib"
],
"publishConfig": {
"access": "private"
},
"repository": {
"type": "git",
"url": "git+https://github.com/mpiroc/my-repo.git"
},
"bugs": {
"url": "https://github.com/mpiroc/my-repo/issues"
},
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"test": "jest",
"lint": "eslint --ext .ts .",
"bundle": "parcel build lib/index.ts --no-source-maps --target node --bundle-node-modules --no-minify"
},
"jest": {
"preset": "ts-jest",
"globals": {
"ts-jest": {
"packageJson": "package.json"
}
},
"testEnvironment": "node",
"testMatch": [
"**/__tests__/**/*.(spec|test).ts?(x)",
"**/?(*.)+(spec|test).ts?(x)"
]
},
"dependencies": {
"@mpiroc/my-internal-dep-1": "0.0.0",
"@mpiroc/my-internal-dep-2": "0.0.0"
},
"devDependencies": {
"@types/jest": "^24.0.18",
"@types/node": "^10.14.20",
"@typescript-eslint/eslint-plugin": "^2.3.2",
"@typescript-eslint/eslint-plugin-tslint": "^2.3.2",
"@typescript-eslint/parser": "^2.3.2",
"@typescript-eslint/typescript-estree": "^2.3.2",
"eslint": "^6.5.0",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-node": "^10.0.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"jest": "^24.9.0",
"parcel-bundler": "^1.12.4",
"ts-jest": "^24.1.0",
"tslint": "^5.20.0",
"typescript": "^3.6.3",
"typescript-tslint-plugin": "^0.5.4"
}
}
`npm run bundle`
# Which in turn runs:
parcel build lib/index.ts --no-source-maps --target node --bundle-node-modules --no-minify
Because Rush uses PNPM under the hood, I've added the following workaround for https://github.com/parcel-bundler/parcel/issues/1125 (in .npmrc):
# Workaround for https://github.com/parcel-bundler/parcel/issues/1125.
# TODO: Remove once parcel#1125 is fixed.
shamefully-flatten=true
parcel build completes successfully.
parcel build fails due to module not found: babel-types
The real solution is to either add babel-types to parcel's dependencies, or remove the runtime dependency on babel-types.
In the meantime, the workaround is to use pnpm's readPackage hook to fill in the missing dependency:
// In `pnpmfile.js`, function `readPackage`
if (packageJson.name === 'parcel-bundler') {
packageJson.dependencies['babel-types'] = '^6.26.0'
context.log('Added missing dependency (babel-types) to parcel-bundler')
}
I am attempting to use Parcel to bundle some packages (which will be deployed to AWS Lambda) in my Rush-based monorepo.
See https://github.com/microsoft/rushstack/issues/1578 for a full minimal repro. You can find the repro project here: https://github.com/mpiroc/rush-repro
| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | "parcel-bundler": "^1.12.4" |
| Node | 10.16.3 (also tested on non-LTS 12.6.0) |
| npm/Yarn | "pnpmVersion": "2.15.1" |
| Operating System | Windows 10 version 1903 build 18362.356 |
PS E:\Projects\p2p-javascript-based-mmorpg-game> yarn workspace client run dev
(node:10940) UnhandledPromiseRejectionWarning: Error: A package is trying to access another package without the second one being listed as a dependency of the first one
Required package: babel-types (via "babel-types")
Required by: parcel-bundler@npm:1.12.4 (via /E:/Projects/p2p-javascript-based-mmorpg-game/.yarn/unplugged/parcel-bundler-npm-1.12.4-a8e54cfc66/node_modules/parcel-bundler/src/)
Require stack:
- E:\Projects\p2p-javascript-based-mmorpg-game\.yarn\unplugged\parcel-bundler-npm-1.12.4-a8e54cfc66\node_modules\parcel-bundler\src\Asset.js
- E:\Projects\p2p-javascript-based-mmorpg-game\.yarn\unplugged\parcel-bundler-npm-1.12.4-a8e54cfc66\node_modules\parcel-bundler\src\assets\RawAsset.js
- E:\Projects\p2p-javascript-based-mmorpg-game\.yarn\unplugged\parcel-bundler-npm-1.12.4-a8e54cfc66\node_modules\parcel-bundler\src\Parser.js
- E:\Projects\p2p-javascript-based-mmorpg-game\.yarn\unplugged\parcel-bundler-npm-1.12.4-a8e54cfc66\node_modules\parcel-bundler\src\Bundler.js
- E:\Projects\p2p-javascript-based-mmorpg-game\.yarn\unplugged\parcel-bundler-npm-1.12.4-a8e54cfc66\node_modules\parcel-bundler\src\cli.js
- E:\Projects\p2p-javascript-based-mmorpg-game\.yarn\unplugged\parcel-bundler-npm-1.12.4-a8e54cfc66\node_modules\parcel-bundler\bin\cli.js
at Object.makeError (E:\Projects\p2p-javascript-based-mmorpg-game\.pnp.js:13535:24)
at resolveToUnqualified (E:\Projects\p2p-javascript-based-mmorpg-game\.pnp.js:22398:35)
at resolveRequest (E:\Projects\p2p-javascript-based-mmorpg-game\.pnp.js:22475:27)
at Object.resolveRequest (E:\Projects\p2p-javascript-based-mmorpg-game\.pnp.js:22543:26)
at Function.module_1.Module._resolveFilename (E:\Projects\p2p-javascript-based-mmorpg-game\.pnp.js:21773:34)
at Module.require (internal/modules/cjs/loader.js:1040:19)
at require (E:\Projects\p2p-javascript-based-mmorpg-game\.yarn\cache\v8-compile-cache-npm-2.1.0-86ea69cdd0-1.zip\node_modules\v8-compile-cache\v8-compile-cache.js:161:20)
at Object.<anonymous> (E:\Projects\p2p-javascript-based-mmorpg-game\.yarn\unplugged\parcel-bundler-npm-1.12.4-a8e54cfc66\node_modules\parcel-bundler\src\Asset.js:12:11)
at Module._compile (E:\Projects\p2p-javascript-based-mmorpg-game\.yarn\cache\v8-compile-cache-npm-2.1.0-86ea69cdd0-1.zip\node_modules\v8-compile-cache\v8-compile-cache.js:194:30)
(node:10940) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:10940) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process
with a non-zero exit code.
I got same error with Yarn.
Same issue with a yarn@berry + parcel@latest + typescript project.
By manually add dependency babel-types to the project, parcel could successfully build & serve. However, it still can't resolve typescript syntax even with adding dependency @babel/preset-typescript or something else. :disappointed:
Adding babel-types to the dependencies with yarn v2 didn't work for me. Are there any other workarounds?
Yarn v2 isn鈥檛 supported by parcel at the monent there鈥檚 an open PR for it
Sent with GitHawk
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.
Most helpful comment
Yarn v2 isn鈥檛 supported by parcel at the monent there鈥檚 an open PR for it
Sent with GitHawk