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.

Use of npm instead of yarn fails

See original GitHub issue

Hello guys, first time trying projen. I would like to create a CDK V2 TypeScript project with npm (I don’t have yarn installed). I first had much trouble finding how to use npm instead of yarn. It is actually implemented but not documented (yet?): --package-manager npm

So using projen latest version, I executed this command to generate the project:

npx projen new awscdk-app-ts --package-manager npm --projenrc-ts --cdk-version v2.0.0-rc.1

So far, so good. The project is generated. However, when I try to build it with the build npm script, I get this error:

> Executing task: npm run build <


> aws-codepipeline-custom-trigger-cdk@0.0.0 build
> npx projen build

🤖 build | npx projen
🤖 default | ts-node .projenrc.ts
🤖 Synthesizing project...
🤖 yarn install --check-files
Error: Command failed: yarn install --check-files
/bin/sh: yarn: command not found

    at checkExecSyncError (child_process.js:616:11)
    at Object.execSync (child_process.js:652:15)
    at Object.exec (/Users/ajo/Projects/Tests/aws-codepipeline-custom-trigger-cdk/node_modules/projen/src/util.ts:10:24)
    at NodePackage.postSynthesize (/Users/ajo/Projects/Tests/aws-codepipeline-custom-trigger-cdk/node_modules/projen/src/node-package.ts:646:5)
    at AwsCdkTypeScriptApp.synth (/Users/ajo/Projects/Tests/aws-codepipeline-custom-trigger-cdk/node_modules/projen/src/project.ts:395:14)
    at Object.<anonymous> (/Users/ajo/Projects/Tests/aws-codepipeline-custom-trigger-cdk/.projenrc.ts:16:9)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Module.m._compile (/Users/ajo/Projects/Tests/aws-codepipeline-custom-trigger-cdk/node_modules/ts-node/src/index.ts:1056:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/ajo/Projects/Tests/aws-codepipeline-custom-trigger-cdk/node_modules/ts-node/src/index.ts:1059:12)
🤖 Synthesis failed: Task "default" failed when executing "ts-node .projenrc.ts" (cwd: /Users/ajo/Projects/Tests/aws-codepipeline-custom-trigger-cdk)
🤖 Task "build" failed when executing "npx projen" (cwd: /Users/ajo/Projects/Tests/aws-codepipeline-custom-trigger-cdk)
npm ERR! code 1
npm ERR! path /Users/ajo/Projects/Tests/aws-codepipeline-custom-trigger-cdk
npm ERR! command failed
npm ERR! command sh -c npx projen build

So, it looks like a bunch of scripts (found in the .projen/tasks.json file) use yarn instead of npm (well, actually there is no reference at all to npm in these scripts).

Should I conclude that npm is not (yet) supported ?

Thanks !

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
mmcculloh-dmscommented, May 8, 2021

As a workaround for /bin/sh: yarn: command not found, if you use --no-post you can avoid the post install that would normally fail without yarn:

npx projen new awscdk-app-ts --projenrc-ts --cdk-version v2.0.0-rc.1 --no-post

So you can change the package manager in .projenrc.ts manually before running anything. Make sure to run npm i before npm run projen as you’ll need ts-node.

1reaction
Chriscbrcommented, May 8, 2021

So the question is: how do I bootstrap a project with npm ?

For now I think the first way you listed (with --package-manager npm) is the most correct – you just have to manually update .projenrc.ts after you get started.

I forgot about this before, but if you run npx projen new awscdk-app-ts --help, it don’t actually show the --package-manager option because it isn’t explicitly supported – this is because of a small technical issue. (Right now only string, number, and boolean typed options are accepted as CLI args, because we support projenrc files in multiple languages). It could be possible to fix this, but it requires taking a closer look at how we are processing arguments and using jsii.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to make create-react-app use npm instead of yarn?
You can either. 1) Remove yarn.lock , and running npm i ,. or. 2) Run create-react-app app --use-npm.
Read more >
How to Force Use Yarn or NPM - freeCodeCamp
In this short post, I'm going to show you how to prevent the usage of npm or yarn, depending on your needs. This...
Read more >
Yarn vs npm: Everything You Need to Know - SitePoint
Yarn stands for Yet Another Resource Negotiator. The Yarn package manager is an alternative to npm, released by Facebook in October 2016. The ......
Read more >
Migrating from npm - Yarn
When other people start using Yarn instead of npm , the yarn.lock file will ensure that they get precisely the same dependencies as...
Read more >
Allow use of npm instead of yarn (eg --use-npm flag) #2904
Issue details I am behind a proxy and can't use yarn. Please introduce a way to use npm instead of yarn install when...
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