Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
5393 votes
22 answers
1.9m views

What's the difference between tilde(~) and caret(^) in package.json?

After I upgraded to the latest stable node and npm, I tried npm install moment --save. It saves the entry in the package.json with the caret ^ prefix. Previously, it was a tilde ~ prefix. Why are ...
Fizer Khan's user avatar
  • 91.3k
2923 votes
16 answers
1.0m views

What's the difference between dependencies, devDependencies, and peerDependencies in NPM package.json file?

This documentation answers my question very poorly. I didn't understand those explanations. Can someone say in simpler words? Maybe with examples if it's hard to choose simple words? Also added ...
Vitalii Korsakov's user avatar
930 votes
34 answers
577k views

Is there a way to get the version from the 'package.json' file in Node.js code?

Is there a way to get the version set in the package.json file in a Node.js application? I would want something like this var port = process.env.PORT || 3000 app.listen port console.log "Express ...
Abhik Bose Pramanik's user avatar
674 votes
14 answers
413k views

How to find unused packages in package.json?

Is there a way to determine if you have packages in your package.json file that are no longer needed? For instance, when trying out a package and later commenting or deleting code, but forgetting to ...
Josh C's user avatar
  • 8,121
620 votes
22 answers
1.0m views

How to set environment variables from within package.json?

How to set some environment variables from within package.json to be used with npm start like commands? Here's what I currently have in my package.json: { ... "scripts": { "help": "tagove ...
dev.meghraj's user avatar
  • 8,960
497 votes
5 answers
148k views

How do I decide whether @types/* goes into `dependencies` or `devDependencies`?

I use TypeScript 2 in my project. I'd like to use some js library, but also typings for that library. I can install types with simple npm install @types/some-library. I'm not sure if I should --save ...
kamyl's user avatar
  • 6,206
366 votes
46 answers
574k views

Field 'browser' doesn't contain a valid alias configuration

I've started using webpack2 (to be precise, v2.3.2) and after re-creating my config I keep running into an issue I can't seem to solve I get (sorry in advance for ugly dump): ERROR in ./src/main.js ...
Matthew Herbst's user avatar
339 votes
8 answers
135k views

Move a module from devDependencies to dependencies in npm package.json

Is there any short command to move a module from devDependencies to dependencies in package.json? I find myself always doing this: npm uninstall <module_name> --save-dev npm install <...
Emad Emami's user avatar
  • 6,459
299 votes
13 answers
360k views

npm install private github repositories by dependency in package.json

I'm trying to install github private repository by npm that includes other private github repositories as dependency. Have tried a lot of ways and posts but none is working. Here is what i'm doing : ...
vashishatashu's user avatar
296 votes
8 answers
201k views

How to use private Github repo as npm dependency

How do I list a private Github repo as a "dependency" in package.json? I tried npm's Github URLs syntaxes like ryanve/example, but doing npm install in the package folder gives "could not install" ...
ryanve's user avatar
  • 51.8k
287 votes
4 answers
173k views

Do I need both package-lock.json and package.json?

After updating my NPM to the latest version (from 3.X to 5.2.0) and running npm install on an existing project, I get an auto-created package-lock.json file. I can tell package-lock.json gives me an ...
Omri Luzon's user avatar
  • 4,155
211 votes
2 answers
125k views

What is the "module" package.json field for?

I've seen some npm packages (vue for example) have a module field in their package.json. But module is not included in the package.json documentation - is this a convention of some kind? Is there ...
ryanve's user avatar
  • 51.8k
188 votes
15 answers
224k views

Module not found: Error: Can't resolve 'core-js/es6'

I've got a problem with my build process in relation to my React app. I always get the following error: Module not found: Error: Can't resolve 'core-js/es6' if I use this in a polyfill.js: import '...
Gutelaunetyp's user avatar
  • 2,092
178 votes
7 answers
201k views

How to install only "devDependencies" using npm

I am trying to install ONLY the "devDependencies" listed in my package.json file. But none of the following commands work as I expect. All of the following commands install the production dependencies ...
Nesan Rajendran's user avatar
178 votes
27 answers
209k views

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/tokenize' is not defined by "exports" in the package.json of a module in node_modules

This is a React web app. When I run npm start This error occurred > [email protected] start > react-scripts start node:internal/modules/cjs/loader:488 throw e; ^ Error [...
Julian Chu's user avatar
  • 1,990
178 votes
17 answers
111k views

How to npm publish specific folder but as package root

I have a project that include a gulp task for building and packaging the sources and release in a directory called dist. My goal is publish it as a npm package, but only my dist folder. The npm ...
robsonrosa's user avatar
  • 2,658
177 votes
5 answers
177k views

npm equivalent of yarn resolutions?

Is there an npm equivalent of the yarn resolutions functionality? There is no mention of it in the npm package.json docs. For example, I want to install [email protected] and one of its dependencies (@lerna/...
adanilev's user avatar
  • 3,268
139 votes
9 answers
108k views

npm update does not do anything

When I execute this code in my application folder where the package.json is located: npm update or npm update --save-dev it does not do anything. But when I do npm outdated is shows many outdated ...
Elisabeth's user avatar
  • 21k
128 votes
51 answers
309k views

Error: EPERM: operation not permitted, unlink 'D:\Sources\**\node_modules\fsevents\node_modules\abbrev\package.json'

I just updated npm to 5.4.0. Now, Whenever I want install a npm package I get the following error: D:\Sources\DownloadCms\Md.Download\Web.Angular>npm install mds.angular.datetimepicker@latest --...
127 votes
5 answers
222k views

What is the cause of "npm WARN EBADENGINE"?

When generating a package-lock.json file using npm install, I get this error: npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '[email protected]', npm WARN EBADENGINE required: { ...
calyxofheld's user avatar
  • 1,988
127 votes
11 answers
157k views

How to use environment variables in package.json

Because we don't want sensitive data in the project code, including the package.json file, using environment variables would be a logical choice in my opinion. Example package.json: "...
kaasdude's user avatar
  • 1,436
121 votes
2 answers
137k views

How to specify the path of `package.json` to npm?

I use npm scripts to build my project. I'd like to be able to run the scripts from a different directory. That is, instead of doing the following: cd project; npm run build; cd .. ...I'd like to ...
rinogo's user avatar
  • 8,893
117 votes
2 answers
144k views

Node engine 8.x or 10.x in package.json

I tried to specify the node engine in a package.json to accept both 8 and 10 version. I tried to type this: "engines": { "node": "8.x|10.x" }, But running yarn results in: The engine "node" is ...
rap-2-h's user avatar
  • 31.4k
117 votes
3 answers
53k views

What is `"dev" true` in package-lock.json for?

What does "dev" true means in package-lock.json file? In my case it is automatically updated when I perform npm operations. How can we remove it?
Mustafa bw's user avatar
  • 1,422
112 votes
3 answers
92k views

Change working directory for npm scripts

Q: Is it possible to change the the context in which npm runs scripts? What I want to is the following: "scripts": { "test": "gulp mocha", "pre-install": "./deps/2.7/cpython/configure --prefix=...
eljefedelrodeodeljefe's user avatar
108 votes
3 answers
165k views

What does "npm audit fix" exactly do?

npm audit fix is intended to automatically upgrade / fix vulnerabilities in npm packages. However, I haven't found out what it exactly does to fix those vulnerabilities. I assumed that npm audit fix ...
Sampo's user avatar
  • 4,798
107 votes
3 answers
31k views

Make `npm install --save` add a strict version to package.json

When you run npm install --save somepackage, it usually adds something like this into package.json: "dependencies": { "somepackage": "^2.1.0" } Because the version is prepended with a caret(^), ...
twiz's user avatar
  • 10.1k
99 votes
1 answer
42k views

How do you use the 'files' and 'directories' properties in package.json?

If a package.json has a files prop, and/or a directories prop: "files": [ "./src/assets/fonts/" ], "directories": { "assets:": "./src/assets" } What are some ways to make use of ...
Baz's user avatar
  • 2,257
95 votes
7 answers
97k views

Root directory in package.json

My question concerns an existing library that I wish to publish as an NPM module. The library is already in use, and currently required via the local file system. How can I specify the root directory ...
Drahcir's user avatar
  • 11.9k
94 votes
2 answers
50k views

How can I reference package version in npm script?

I want to reference my package version in a npm script so I can show current version in the app. Something like { "name": "bla", "version": "1.0.0", "author": "bla bla", "scripts": { "...
Evaldo Bratti's user avatar
87 votes
10 answers
177k views

How to use package.json scripts to copy files with specific file extension

I am trying out npm as a build tool. One stumbling block I have encountered is that I need to copy javascript files from one folder to another. The source folder contains typescript files, javascript ...
Thomas Jørgensen's user avatar
84 votes
1 answer
91k views

npm: How to just run postinstall?

In my node.js project, how could I just run the postinstall script, without running install before? FYI, this is my package.json : { "name": "gestionclientjs", ..., "...
noelm's user avatar
  • 1,302
72 votes
4 answers
86k views

How to set env var for .npmrc use

I need a module in my project to download a private npm package. To accomplish this, I am using a .npmrc file to supply a read-only token needed to download the package. To keep the token supplied by ...
skwny's user avatar
  • 3,080
66 votes
4 answers
36k views

npm package.json OS specific script

I would like to create a package.json build script that executes slightly different set of commands when run from Windows, Linux, Mac. The problem is that I cannot find a way to put it in package....
gawi's user avatar
  • 2,922
61 votes
4 answers
56k views

Is the "files" property necessary in package.json?

It looks like the package will include all files (that are not ignored), even if the package.json has no "files" array. Is that property necessary?
P Varga's user avatar
  • 19.9k
56 votes
11 answers
41k views

How can I display the current app version from package.json to the user using Vite?

With create-react-app one could use process.env.REACT_APP_VERSION for this. Is there an equivalent in Vite?
Obiwahn's user avatar
  • 2,935
55 votes
12 answers
78k views

Pass command line -- argument to child script in Yarn

I have a package.json that looks similar to this: "scripts": { "dev": "cross-env BABEL_ENV=client webpack --config webpack/client.development.js && yarn dev:stub-server | cross-env ...
Luciano M. L.'s user avatar
55 votes
6 answers
44k views

Import from subfolder of npm package

I've been working on creating a small library of React components for use in several other projects. I am publishing the package internally (using a private GitHub repository) and then including in ...
Kendall's user avatar
  • 2,112
53 votes
3 answers
43k views

What is the correct way of adding `react` as a dependency in the `package.json` of a reusable components library?

I built a few reusable React components, and I want to know the correct way to add react as a dependency in my package.json for the purpose of publishing to the npm registry. I am currently doing this:...
svnm's user avatar
  • 23.9k
53 votes
5 answers
41k views

Is there a way to specify angular version with the ng new command

I am creating a new Angular project and would like all the Angular dependencies to be from the stable 7th version. However, it seems that while running the ng new app command the Angular always ...
Saurabh Tiwari's user avatar
50 votes
4 answers
108k views

Pass command line args to npm scripts in package.json

I have the below scripts in my package.json: "scripts": { "vumper": "node node_modules/vumper/index.js", "format": "prettier --single-quote -width=80 --write package.json" }, The 'vumper' ...
Tony Scialo's user avatar
  • 5,797
48 votes
4 answers
99k views

Cannot find module 'prettier'

I updated all packages but still getting this error after running npm run serve: Module build failed (from ./node_modules/eslint-loader/index.js): Error: Cannot find module 'prettier' Occurred ...
Tom's user avatar
  • 5,852
47 votes
3 answers
19k views

How to list all the commands available in package.json?

A package.json can have lot of commands and common ones are npm start, npm test but there are generally more commands. Is there a way to list all the commands? Currently I use less package.json but ...
igauravsehrawat's user avatar
45 votes
2 answers
18k views

Is node-sass a dev or a production dependency on React projects?

In variaous React documentation I see it being added as a prod dependency but I'm not understanding why. Shouldn't it be a devDependecy since SASS only gets compiled during development and when pushed ...
user avatar
43 votes
4 answers
17k views

What naming convention do I use for scripts in package.json?

In package.json I have this script name with two words lint and fix. How should I make a right name? There are options: lowerCamelCase - lintFix UpperCamelCase - LintFix snake_case - lint_fix kebab-...
galkin's user avatar
  • 5,432
43 votes
4 answers
19k views

Github Action different between release created and published

since Github Releases are actually a Git Tags, I want to auto-upgrade my package.json version when there is a new Release (and tag), with Github Action. I know I need to trigger a job on: release, ...
baruchiro's user avatar
  • 5,618
43 votes
3 answers
23k views

What exactly does "next" mean in package.json dependencies?

What exactly does next mean in package.json dependencies? "dependencies": { "react": "^15.4.2", "react-dom": "^15.4.2", "react-router-dom": "next" }
zok's user avatar
  • 7,464
41 votes
6 answers
62k views

Solve having more than one copy of React in the same app

I'm developing a React module locally. For that, I'm linking my module using npm link. The module is imported successfully but hooks are failing inside the module. It's throwing the following error: ...
Rashomon's user avatar
  • 6,612
39 votes
4 answers
27k views

how to execute powershell ps1 scripts from package.json "scripts"?

How can I execute PowerShell ps1 scripts from package.json "scripts"? I know how to set up a basic script in package.json "scripts". For example with the following configuration, I can exec npm run ...
user8570495's user avatar
  • 1,805
39 votes
5 answers
32k views

Do yarn workspaces work with npm, too?

I checked out a repo which uses yarn instead of npm as build tool. in the package.json, it defines workspaces to deal with multiple sub-projects: { "workspaces": [ "packages/*" ], "...
helt's user avatar
  • 5,107

1
2 3 4 5
33