Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parcel wipes out Package.json when installing dependencies #7271

Open
wesbos opened this issue Nov 9, 2021 · 29 comments
Open

Parcel wipes out Package.json when installing dependencies #7271

wesbos opened this issue Nov 9, 2021 · 29 comments
Assignees

Comments

@wesbos
Copy link

wesbos commented Nov 9, 2021

Just lost a bunch of work I did on my package.json.

I am running parcel 2.0.1, which was released yesterday to fix an issue with dependencies not being installed.

I have targets in my package.json like this:

    "css": {
      "source": [
        "./public/stylesheets/style-ARG.styl",
        "./public/stylesheets/account.styl"
      ],
      "distDir": "./public/stylesheets/build"
    },

When I run parcel, it says Installing @parcel/transformer-stylus...

Then it both wipes out everything in my node_modules directory, and wipes out everything in my package.json and replaces it with:

{
  "devDependencies": {
    "@parcel/transformer-stylus": "^2.0.1"
  }
}

Probably something to do with the new way you are saving deps?

Pre-installing @parcel/transformer-stylus does not fix it either, same thing.

I assume this is also happening with sass and other transformers

@devongovett
Copy link
Member

Parcel doesn't edit package.json, it just runs a package manager like yarn or npm, which may edit the package.json to add the dependency. Not sure what would be causing it to be removed completely. Could you provide more details? Are you using Yarn or NPM? What versions? Are you in a monorepo? What directory are you running Parcel from? Is it the project root with the package.json/lockfile, a sub directory, or outside?

This sounds similar to #2978, which I thought was fixed, but maybe there's another case.

@devongovett
Copy link
Member

Btw you can run with the --no-autoinstall flag to prevent automatic installation from being run, which might be a workaround while we figure this out.

@wesbos
Copy link
Author

wesbos commented Nov 9, 2021

Thanks Devon, I'm running it from the root directory where the package.json is, npm 7.15.1, node 16.3, no monorepo.

running it with --no-autoinstall and @parcel/transformer-stylus installed, gives me this error:

  > 24 |     "*.{styl,stylus}": ["@parcel/transformer-stylus"],
  >    |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Cannot find module "@parcel/transformer-stylus

@devongovett
Copy link
Member

Hmm strange. So I made a example project with these files:

package.json:

{
  "name": "test",
  "scripts": {
    "build": "parcel build test.styl"
  },
  "dependencies": {
    "parcel": "^2.0.1"
  }
}

test.styl:

.foo
  background: red

I first ran npm install to install Parcel, then I ran npm run build. It auto installed @parcel/transformer-stylus and built successfully. The plugin was added as a dev dependency to my package.json and the other fields were left untouched. Also tried with targets similar to how you had configured it. I have npm 7.20.3 and node 16.6.1 btw.

Is there some other possible way to reproduce or some other detail of your setup that I missed? Maybe you have a package.json in a parent directory or something that is causing npm to be confused? Maybe some kind of symlink? I'm kinda grasping at straws here... It seems Parcel cannot find @parcel/transformer-stylus even when it is installed which is strange. Did you try just opening the node repl and trying to require it?

@wesbos
Copy link
Author

wesbos commented Nov 9, 2021

Let me try replicate it outside my project. I've been trying to delete files from my build to see if it's one of them causing the issue and I dont see anything change.

image

@wesbos
Copy link
Author

wesbos commented Nov 9, 2021

@devongovett I'm able to replicate it here: https://github.com/wesbos/parcel-issue-replication

@devongovett
Copy link
Member

Hmm, it works for me... 😅

Let me ask and see if anyone else on the core team can reproduce.

Does it change if you clone that repo into a different directory? I'm wondering if something in a parent directory of your project is causing a problem somehow...

@wesbos
Copy link
Author

wesbos commented Nov 9, 2021

Shoot eh.

I tried it in the very root of my computer, same issue.

I do get this error, could it be related?

Error: Could not resolve module "wrap-ansi" from "/Users/wesbos/parcel-issue-replication/node_modules/@parcel/reporter-cli/lib/CLIReporter.js"

Here is a video of me having the issue: https://share.getcloudapp.com/4guPZ1Om

@edm00se
Copy link

edm00se commented Nov 9, 2021

@wesbos FWIW, the repro repo works for me (clone, install, run, w/ no deleted node_modules, no wiped package.json). Node 16.13.0, npm 8.1.2, on macOS (11.6 Big Sur).

Do you have any custom npm config or something crazy in your ~/.npmrc?

@wesbos
Copy link
Author

wesbos commented Nov 9, 2021

GOT IT!

I had a rouge package-lock.json file in my computers root directory. It didn't have anything to do with parcel in it, but it was causing it.

Ugh, thank you for your help. you were right with the parent files.

@wesbos wesbos closed this as completed Nov 9, 2021
@devongovett
Copy link
Member

Ah nice. I can reproduce if I add a package-lock.json file in a parent directory as well. I wonder if there's anything we can do to prevent this from happening. It doesn't happen if I just run npm install @parcel/transformer-stylus --save-dev though, which I thought was all Parcel is doing, so must be something about how we're invoking npm... Or if there's nothing we can do, maybe we could detect this extra package-lock.json file and fail with a nice message instead of letting npm nuke the package.json. Definitely something to improve here. Going to reopen and I'll investigate more.

@devongovett devongovett reopened this Nov 9, 2021
@devongovett devongovett self-assigned this Nov 16, 2021
@asanteb
Copy link

asanteb commented Nov 16, 2021

This exact issue is happening to me. parcel build succeeds on my personal Macbook and Ubuntu computer but when I try the command in my webserver (also running Ubuntu 20.04) it fails and rewrites my package.json. Doesn't matter if package-lock.json is present or not. My package.json is constantly rewritten to

{
  "devDependencies": {
    "@parcel/transformer-sass": "^2.0.1"
  }
}

I am using index.html as my source which references an scss style file. This was working before in my server but now it has just borked all of my builds

@charlespeary
Copy link

charlespeary commented Nov 16, 2021

I battled a similar issue for the past two days with the following error:

Building...
🚨 Build failed.

@parcel/core: Cannot find Parcel plugin "@parcel/transformer-typescript-types"

  /var/jenkins_home/workspace/Deploy---Generating_temp_packages/LoadNinja-Shared/node_modules/@parcel/config-default/index.json:4:26
    3 |   "transformers": {
  > 4 |     "types:*.{ts,tsx}": ["@parcel/transformer-typescript-types"],
  >   |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Cannot find module "@parcel/transformer-typescript-types"
    5 |     "bundle-text:*": ["...", "@parcel/transformer-inline-string"],
    6 |     "data-url:*": ["...", "@parcel/transformer-inline-string"],

As in the @asanteb case, it worked fine on my local machine but failed inside a Jenkin's job.
I had a package-lock.json in my parent directory and removing it fixed the issue.

Node version: v14.17.0
Npm version: 6.14.13

@LuisBoehme
Copy link

LuisBoehme commented Nov 17, 2021

Also had similar issue! Deleted yarn.lock in current AND parent directory, and it fixed the issue!

Thank you for figuring it out guys!

@antoniojss-idx
Copy link

`@parcel/core: Cannot find Parcel plugin "@parcel/transformer-typescript-types"

......../node_modules/@parcel/config-default/index.json:4:26
3 | "transformers": {

4 | "types:.{ts,tsx}": ["@parcel/transformer-typescript-types"],
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Cannot find module "@parcel/transformer-typescript-types"
5 | "bundle-text:
": ["...", "@parcel/transformer-inline-string"],
6 | "data-url:*": ["...", "@parcel/transformer-inline-string"],`

In my case I am adding the --no-autoinstall option, the transformer library is installed and, even though, I am having this issue.

If I remove the option, no matter if the transformer library is installed or not, Parcel tries to install it and remove my package.json.

macOS Monterey.
Node v12.22.1

I am using Azure as artifact repo so I have a .npmrc file pointing to two Azure artifacts repos.

@ojame
Copy link

ojame commented Dec 5, 2021

I had a package-lock.json file in a parent directory but it wasn't the direct parent; so make sure you look all the way up the tree. Thanks @wesbos!

@michaelpumo
Copy link

michaelpumo commented Dec 20, 2021

GOT IT!

I had a rouge package-lock.json file in my computers root directory. It didn't have anything to do with parcel in it, but it was causing it.

Ugh, thank you for your help. you were right with the parent files.

I can confirm that this solution worked for me. There was a package-lock.json file in my computer root. Once removed, it allows the build to happen.

Very strange and not idea at all. I guess it shouldn't be even looking outside its own route directory, that's madness.

Any way to force it to only look for local installed dependencies instead of recursively searching upwards? This file was not in the parent and actually 3 levels up.

@q-rault
Copy link

q-rault commented Jan 26, 2022

Came to also confirm, Thanks to wesbos for finding the root cause :

  • Also had a package.json in a parent dir,

  • Got this message in the console as a result (followed by a bunch of related errors) :
    Error: Could not resolve module "wrap-ansi" from "/Users/qrault/Projects/simplefolio/node_modules/@parcel/reporter-cli/lib/CLIReporter.js

  • as a result, destroyed everything but @parcel/transformer-sass in my package-json

  "devDependencies": {
    "@parcel/transformer-sass": "^2.0.1"

Deleting package.json in the parent directory resolved the issue

@lucasdavidferrero
Copy link

lucasdavidferrero commented Feb 27, 2022

I faced this issue with yarn 1 on Windows 10. My solution was to update yarn to version 3 and delete any package.json, package-lock.json and yarn.lock file located in the user folder (C:\Users\YourProfileName)

@pklaschka
Copy link

pklaschka commented Mar 6, 2022

Not quite sure how this is related, but deleting a package-lock.json I found 3 levels higher up my file tree (Windows 10, Parcel v2.3.2, NodeJS v16) solved all kinds of weird behavior when running parcel, including but not limited to #5365, for me.

My best guess is that a lock file higher up the file tree puts Parcel into some kind of undefined state, where all kinds of things act strangely? Not sure. But this could be related to a lot of "weird behavior" issues (and solve more than this one error behavior) 🤔 .

@roelvanduijnhoven
Copy link

Thanks @pklaschka. Also for me this was caused by a packge-lock.json file in a directory somewhere up in the tree.

@crypticspaghetti
Copy link

I was having troubles getting a project I cloned to work:

🚨 Build failed.

@parcel/core: Cannot find Parcel plugin "@parcel/transformer-sass"

  /home/crypticspaghetti/Code/github/crypticspaghetti/simplefolio/node_modules/@parcel/config-default/index.json:25:23
    24 |     "*.{styl,stylus}": ["@parcel/transformer-stylus"],
  > 25 |     "*.{sass,scss}": ["@parcel/transformer-sass"],
  >    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^ Cannot find module "@parcel/transformer-sass"

The module in question was installed already so it had me scratching my head for a while.

The comments in this issue pointed me in the right direction. Mine was related to a rogue yarn.lock file in my home directory. This also had the effect of causing the autoinstall to use Yarn when I was running the build with NPM. Removing the lock-file solved all the issues for me!

@dlmarshall3
Copy link

Yep, confirmed it was a rogue package.json. Four levels up. What in the world.

@edm00se
Copy link

edm00se commented May 17, 2023

Gandalf saying “go back to the shadow”

@github-actions github-actions bot removed the Stale Inactive issues label May 17, 2023
@yami-shiftasia
Copy link

yami-shiftasia commented Oct 20, 2023

I have same issue, when pnpm install in root of monorepos project

@eliliam
Copy link

eliliam commented Oct 20, 2023

I have the same issue as @yami-shiftasia, for us this is causing parcel to somehow not detect our .babelrc file in one of the monorepo modules.

my-monorepo/ 
|─ pnpm-workspace.yaml
|─ package.json
|─ .parcel-cache/
|─ back-end/
|    |─ package.json
|    |─ src/
|    |    |─ index.js
|─ front-end/
|    |─ package.json            # This is where parcel is installed
|    |─ .babelrc                # This is the file that is being ignored
|    |─ .parcelrc
|    |─ src/
|    |    |─ index.jsx

We confirmed this by putting random invalid text into the .babelrc file under the front-end directory, which should cause parcel to fail to start or build, however it builds just fine.

We are unable to reproduce this in a non-monorepo environment however, from what we've found it appears as if parcel is running in the root of the monorepo and not in front-end where it should(as that is where it is specified in the package.json), thus we believe it's running at the root level and therefore does not see any .babelrc at the root level since it only exists inside front-end

@github-actions github-actions bot added the Stale Inactive issues label Apr 18, 2024
@edm00se
Copy link

edm00se commented Apr 20, 2024

I'll say it again, bot.

Gandalf saying “go back to the shadow”

@github-actions github-actions bot removed the Stale Inactive issues label Apr 20, 2024
@github-actions github-actions bot added the Stale Inactive issues label Oct 17, 2024
@edm00se
Copy link

edm00se commented Oct 17, 2024

I'll say it again, bot.

Gandalf saying “go back to the shadow”

@github-actions github-actions bot removed the Stale Inactive issues label Oct 17, 2024
@wesbos
Copy link
Author

wesbos commented Oct 17, 2024

thank for keeping our bot overlords at bay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests