question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 4 years ago
  • Reactions:16
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
DeMoorJaspercommented, Feb 18, 2020

Yarn v2 isn’t supported by parcel at the monent there’s an open PR for it

Sent with GitHawk

2reactions
a-typecommented, Feb 18, 2020

Adding babel-types to the dependencies with yarn v2 didn’t work for me. Are there any other workarounds?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use the @babel/types.isStringLiteral function in ... - Snyk
To help you get started, we've selected a few @babel/types.isStringLiteral examples, based on popular ways it is used in public projects.
Read more >
babel/preset-typescript
Indicates that every file should be parsed as TS, TSX, or as TS without JSX ambiguities (depending on the isTSX and disallowAmbiguousJSXLike options)....
Read more >
@babel/template - npm
Generate an AST from a string template.. Latest version: 7.18.10, last published: 3 months ago. Start using @babel/template in your project by running...
Read more >
@embroider/babel-loader-8 | Yarn - Package Manager
This repo implements a new three-stage build system for Ember apps: The first stage achieves backward compatibility by building each classic Ember Addon...
Read more >
Update Vue and related dependencies (major) - autoclosed
An error occurred while retrieving approval data for this merge request. Update Vue and related dependencies (major) - autoclosed.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found