parcel icon indicating copy to clipboard operation
parcel copied to clipboard

Parcel bundler not working for npm module library

Open ocodista opened this issue 2 years ago • 3 comments

🐛 bug report

If I try to install a module pointing to a bundled file generated from parcel build it throws an error.

image

🎛 Configuration (.babelrc, package.json, cli command)

package.json

{
  "name": "parcel-package",
  "version": "1.0.0",
  "description": "Reproduction of parcel error",
  "source": "src/index.ts",
  "main": "dist/main.js",
  "module": "dist/module.js",
  "types": "dist/types.d.ts",
  "bin": {
    "parcel-package": "dist/main.js"
  },
  "scripts": {
    "build": "parcel build",
    "install-module": "npm i -g .",
    "test-module": "parcel-package"
  },
  "author": "Caio Borghi",
  "license": "ISC",
  "dependencies": {
    "chalk": "^5.1.2"
  },
  "devDependencies": {
    "@parcel/packager-ts": "2.8.0",
    "@parcel/transformer-typescript-types": "2.8.0",
    "parcel": "^2.8.0",
    "typescript": ">=3.0.0"
  }
}

🤔 Expected Behavior

It should work after install

😯 Current Behavior

It's not working.

💁 Possible Solution

Understand why NPM cannot run the bundle and fix the issue.

🔦 Context

I'm trying to build a npm module to publish on npm

💻 Code Sample

With this index file and the package.json you're already able to reproduce it.

src/index.ts

import chalk from "chalk"

console.log(chalk.green('This is a test application'))

Simply run:

npm run install-module

Then

npm run test-module

And you'll see the following error

image

🌍 Your Environment

Software Version(s)
Parcel ^2.8.0
Node 18.12.1
npm/Yarn 8.19.2
Operating System Arch linux WSL

ocodista avatar Dec 02 '22 16:12 ocodista

Please provide a reproduction by filling out the issue template

mischnic avatar Dec 02 '22 17:12 mischnic

Comment updated with src/index.ts file and package.json

ocodista avatar Dec 02 '22 17:12 ocodista

Hey @mischnic were you able to check it?

ocodista avatar Dec 03 '22 22:12 ocodista