Parcel depends on undeclared dependency `babel-types`
See original GitHub issue🐛 bug report
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.
🎛 Configuration (.babelrc, package.json, cli command)
The config below is for my real-world project. For a minimal repro, see https://github.com/mpiroc/rush-repro.
.babelrc
I do not have a .babelrc
.
package.json
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 <matthew.pirocchi@gmail.com>",
"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"
}
}
CLI Command
`npm run bundle`
# Which in turn runs:
parcel build lib/index.ts --no-source-maps --target node --bundle-node-modules --no-minify
Other
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
🤔 Expected Behavior
parcel build
completes successfully.
😯 Current Behavior
parcel build
fails due to module not found: babel-types
💁 Possible Solution
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')
}
🔦 Context
I am attempting to use Parcel to bundle some packages (which will be deployed to AWS Lambda) in my Rush-based monorepo.
💻 Code Sample
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
🌍 Your Environment
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 |
Issue Analytics
- State:
- Created 4 years ago
- Reactions:16
- Comments:5 (2 by maintainers)
Yarn v2 isn’t supported by parcel at the monent there’s an open PR for it
Sent with GitHawk
Adding
babel-types
to the dependencies withyarn
v2 didn’t work for me. Are there any other workarounds?