parcel-bundler / parcel

The zero configuration build tool for the web. πŸ“¦πŸš€
https://parceljs.org
MIT License
43.43k stars 2.26k forks source link

[bug] PNPM failed to install Bundler modules automatically #8304

Closed TechQuery closed 1 year ago

TechQuery commented 2 years ago

Parcel detected a PNPM project, but failed to install Bundler modules automatically.

πŸŽ› Configuration

package.json

{
    "source": "source/index.ts",
    "types": "dist/index.d.ts",
    "main": "dist/index.umd.js",
    "module": "dist/index.js",
    "devDependencies": {
        "parcel": "^2.6.2"
    },
    "browserslist": "> 0.5%, last 2 versions, not dead",
    "targets": {
        "main": {
            "optimize": true
        }
    },
    "scripts": {
        "build": "parcel build"
    }
}

πŸ€” Expected Behavior

Install missing Bundler modules automatically as NPM & Yarn projects does.

😯 Current Behavior

pnpm build

Error: Failed to install @parcel/transformer-typescript-types: pnpm failed to install modules

pnpm i @parcel/transformer-typescript-types -D

 WARN  Issues with peer dependencies found . └─┬ @parcel/transformer-typescript-types └─┬ @parcel/plugin └─┬ @parcel/types └─┬ @parcel/cache β”œβ”€β”€ βœ• missing peer @parcel/core@^2.6.2 └─┬ @parcel/fs β”œβ”€β”€ βœ• missing peer @parcel/core@^2.6.2 └─┬ @parcel/types └─┬ @parcel/package-manager β”œβ”€β”€ βœ• missing peer @parcel/core@^2.6.2 └─┬ @parcel/fs β”œβ”€β”€ βœ• missing peer @parcel/core@^2.6.2 └─┬ @parcel/workers └── βœ• missing peer @parcel/core@^2.6.2 Peer dependencies that should be installed: @parcel/core@">=2.6.2 <3.0.0"

πŸ’ Possible Solution

I installed all the missing Bundler modules manually to make it work.

πŸ”¦ Context

idea2app/Idea-React#16

🌍 Your Environment

Software Version(s)
Parcel 2.6.2
Node 14.19.1
PNPM 7.5.0
Operating System Windows 10 Pro 21H1
rsthn commented 2 years ago

I can confirm this is happening to me as well. I have a prroject that seems to use a lot of parcel plugins when first built, and the only workaround is to install each missing dependency manually (the ones I can read in the console), re-run the build/watch and if more errors appear install the next missing dependency.

mischnic commented 1 year ago

Another case is now with Node builtin polyfills:

so

import buffer from "buffer";

console.log(process, buffer);

with

{
  "scripts": {
    "start": "parcel example.js"
  },
  "dependencies": {
    "parcel": "^2.8.2"
  }
}

and pnpm also fails with pnpm failed to install modules

folknor commented 1 year ago

My problem is this issue also happens even if I put this in package.json:

    "alias": {
        "process": false,
        "Buffer": false,
        "buffer": false
    },

EDIT: or

"alias": {
        "process": {
            "global": "{}"
        },
        "Buffer": {
            "global": "{}"
        },
        "buffer": {
            "global": "{}"
        }
    },

parcel still reads the JS, tries to resolve those, and asks pnpm to install them.

Is that a separate issue?

mischnic commented 1 year ago

My problem is this issue also happens even if I put this in package.json:

Are you using a monorepo? For these globals, it needs to be put in the project root package.json (And just process and buffer lower case is enough)

folknor commented 1 year ago

Are you using a monorepo?

I use a separate package.json per project, with zero cross-project relations, workspaces, or anything fancy.

mischnic commented 1 year ago

Then please share a reproduction.

folknor commented 1 year ago

Then please share a reproduction.

Sure, this does it for me. Essentially import { fabric } from "fabric" in a JS file. issue-8304.zip

EDIT: Unzip, pnpm up, and pnpm run deploy should be enough to reproduce.

I didn't try to reduce down the @parcel/* imports in package.json, but I'm fairly sure you've got those under control.

mischnic commented 1 year ago

@folknor

$ pnpm i && pnpm run deploy
 WARN  deprecated w3c-hr-time@1.0.2: Use your platform's native performance.now() and performance.timeOrigin.
 WARN  deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
Packages: +386
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packages are hard linked from the content-addressable store to the virtual store.
  Content-addressable store is at: /Users/niklas/Library/pnpm/store/v3
  Virtual store is at:             node_modules/.pnpm
Progress: resolved 411, reused 385, downloaded 0, added 386, done

devDependencies:
+ @parcel/config-default 2.0.0-nightly.1265 (2.8.3 is available)
+ @parcel/core 2.0.0-nightly.1263 (2.8.3 is available)
+ @parcel/optimizer-cssnano 2.0.0-nightly.1265 (2.8.3 is available)
+ @parcel/packager-css 2.0.0-nightly.1265 (2.8.3 is available)
+ @parcel/packager-html 2.0.0-nightly.1265 (2.8.3 is available)
+ @parcel/packager-raw-url 2.8.4-nightly.2888
+ @parcel/packager-svg 2.8.4-nightly.2888
+ @parcel/packager-xml 2.8.4-nightly.2888
+ @parcel/transformer-css 2.0.0-nightly.1265 (2.8.3 is available)
+ @parcel/transformer-html 2.0.0-nightly.1265 (2.8.3 is available)
+ @parcel/transformer-image 2.8.4-nightly.2888
+ @parcel/transformer-js 2.0.0-nightly.1265 (2.8.3 is available)
+ @parcel/transformer-postcss 2.0.0-nightly.1265 (2.8.3 is available)
+ @parcel/transformer-posthtml 2.0.0-nightly.1265 (2.8.3 is available)
+ @parcel/transformer-raw 2.0.0-nightly.1265 (2.8.3 is available)
+ @parcel/transformer-sass 2.0.0-nightly.1265 (2.8.3 is available)
+ @parcel/transformer-webmanifest 2.8.4-nightly.2888
+ @parcel/transformer-xml 2.8.4-nightly.2888
+ fabric 5.3.0
+ parcel 2.0.0-nightly.1263 (2.8.3 is available)
+ rimraf 4.4.0
+ sharp 0.31.3

Done in 7.3s

> test@1.0.0 deploy /Users/niklas/Downloads/issue-8304
> NODE_ENV=production pnpm run build

> test@1.0.0 build /Users/niklas/Downloads/issue-8304
> pnpm run -s clean && pnpm run parcel:build

> test@1.0.0 parcel:build /Users/niklas/Downloads/issue-8304
> parcel build index.html --no-source-maps --detailed-report 0 --target web

✨ Built in 2.60s

dist/index.html              436 B    537ms
dist/index.5b1a866d.js    301.2 KB    993ms

There is indeed a message if I remove the alias field. What OS are you on?

folknor commented 1 year ago

That is indeed weird. When I tried the testcase on a different computer it works as expected. I must have some kind of local pnpm configuration issue on that computer. Apologies for the confusion.

I run Linux on both.