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.

[Bug] Can't add packages: This command can only be run from within a workspace of your project

See original GitHub issue

I created a folder called hello-world then ran yarn init.

It created a file called package.json with this content:

{
  "name": "hello-world"
}

Then I try to install a package, for example moment: yarn add moment.

I get this error:

Usage Error: This command can only be run from within a workspace of your project (Desktop/hello-world isn't a workspace of /C:/Users/Joel/package.json).

and /C:/Users/Joel/package.json doesn’t exist, because I deleted it to see if it would fix the problem, but it didn’t.

Is there a way to use yarn without dealing with all that workspace thing, I thought I could just replace npm with yarn…

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
bgotinkcommented, Jan 29, 2020

I can reproduce this on my machine (macOS). Creating an empty yarn.lock file in your package directory (i.e. at C:\Users\Joel\Desktop\hello-world\yarn.lock) makes it work.

0reactions
neodoncommented, Aug 23, 2020

I’d like to be able to have multiple packages in my repo without being forced to use workspaces.

This is the best I could do for a repro. Since the yarn command fails, it says the reproduction is invalid. I think you all need to reconsider this requirement for a reproduction using Sherlock when an issue is opened with clear and concise repro instructions.

const fs = require('fs')

fs.writeFileSync('package.json', JSON.stringify({
    name: 'root-package',
    version: '1.0.0'
}))

fs.mkdirSync('sub-package')

fs.writeFileSync('sub-package/package.json', JSON.stringify({
    name: 'sub-package',
    version: '1.0.0'
}))

process.chdir('sub-package')
const output = await yarn(`install`);

expect(output).not.toContain(`Usage Error`);
Read more comments on GitHub >

github_iconTop Results From Across the Web

npm ci can only install packages with an ... - Stack Overflow
The npm ERR! The 'npm ci' command can only install with an existing package-lock.json wasn't a super helpful error in that case.
Read more >
Workspaces - Yarn
Workspaces are a new way to set up your package architecture that's available by default starting from Yarn 1.0. It allows you to...
Read more >
Adding package dependencies to your app - Apple Developer
Add a package dependency. To add a package dependency to your Xcode project, select File > Swift Packages > Add Package Dependency and...
Read more >
Using Python environments in VS Code
An "environment" in Python is the context in which a Python program runs and consists of ... any packages you install are installed...
Read more >
Project Configuration - Nx
If you want to ignore a particular package.json file, exclude it from those tools. For example, you can add !packages/myproject to the workspaces...
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