Questions tagged [package.json]
All npm packages contain a file, usually in the project root, called package.json. This file holds various metadata relevant to the project. This file is used to give information to npm that allows it to identify the project as well as handle the project's dependencies.
package.json
3,485
questions
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 ...
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 ...
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 ...
675
votes
33
answers
1.8m
views
SyntaxError: Cannot use import statement outside a module
I've got an ApolloServer project that's giving me trouble, so I thought I might update it and ran into issues when using the latest Babel. My "index.js" is:
require('dotenv').config()
import ...
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 ...
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 ...
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 ...
436
votes
34
answers
1.5m
views
Start script missing error when running npm start
I'm receiving this error when trying to debug my node application using the npm start command.
Error:
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\\\node.exe" "...
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
...
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 <...
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 :
...
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" ...
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 ...
267
votes
17
answers
184k
views
How to display the app version in Angular?
How do I display the app version in Angular application? The version should be taken from package.json file.
{
"name": "angular-app",
"version": "0.0.1",
....
267
votes
8
answers
368k
views
How to add a custom script to package.json that runs a javascript file?
I want to be able to execute the command script1 in a project directory that will run node script1.js.
script1.js is a file in the same directory. The command needs to be specific to the project ...
261
votes
1
answer
105k
views
What is purpose of the property "private" in package.json?
I'm learning node.js and express, I am wondering what is the property "private" in ./package.json file used for?
227
votes
4
answers
155k
views
What should I put in the license field of package.json if my code is only for use by the company I work for?
NPM 2.11.3
I'm building a library in Node. This library is only for use by the company I am currently working for. I think this means that the license is "None". But when I npm init it wants ...
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 ...
198
votes
13
answers
274k
views
"unexpected token import" in Nodejs5 and babel?
In js file, i used import to instead of require
import co from 'co';
And tried to run it directly by nodejs since it said import is 'shipping features' and support without any runtime flag (https://...
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 '...
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 ...
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 [...
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 ...
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/...
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 ...
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: { ...
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:
"...
123
votes
2
answers
81k
views
What is the significance of browserslist in package.json created by create-react-app
I was asked this in an interview. I could not answer.
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
I can see that Its an array.
"not ie <=11" means will not ...
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 ...
120
votes
10
answers
162k
views
I have a "license" in my package.json, why is npm/yarn saying it is missing?
On running yarn install I see a warning every time that there is no license filed even though I have defined one:
$ jq . package.json
{
"name": "license-example",
"version": "1.0.0",
"main": "...
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 ...
117
votes
9
answers
83k
views
typescript outDir setting in tsconfig.json not working
I can't seem to get the outDir flag working when used in package.json. Directory structure is pretty simple: tsconfig.json at the root level, together with a src/ directory and a single index.ts file ...
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?
112
votes
4
answers
147k
views
How to configure package.json to run eslint script
I am using eslint as a linter for my react project and I would like it to check all of my .js files.
I am able to do this through the script:
"lint": "eslint back/*.js && eslint ...
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=...
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 ...
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(^), ...
104
votes
2
answers
92k
views
What is the test command while creating package.json?
While creating package.json from command line using npm init for creating a module in Node.js, there is a test command field that I don't know about. There's no mention of it in the docs too on ...
99
votes
5
answers
112k
views
Multiple commands in package.json
This command: "start": "node server/server.js" starts my server, but before running this I also want a command to run automatically:
'webpack'.
I want to build a script that can be ...
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 ...
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 ...
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": {
"...
90
votes
29
answers
135k
views
Error when deploying react app and it keeps sayings << Plugin "react" was conflicted between "package.json » eslint-config-react-app » >>
I have been having a little bit of issues when deploying my create react app, as it fails to compile and tells me Plugin "react" was conflicted between "package.json » eslint-config-...
88
votes
2
answers
37k
views
What Does Webpack 4 Expect From A Package With sideEffects: false
Webpack 4 has added a new feature: it now supports a sideEffects flag in the package.json of the modules it is bundling.
From Webpack 4: released today
Over the past 30 days we have worked ...
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 ...
84
votes
24
answers
172k
views
Invalid options object. Dev Server has been initialized using an options object that does not match the API schema
I have been stuck on this error in my project when I add "proxy": "http://localhost:6000"
in my package.json.
This is the error response after yarn start.
Invalid options object. ...
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",
...,
"...
83
votes
8
answers
52k
views
'package.json' is not under 'rootDir'
I'm trying to import package.json in my TypeScript application:
import packageJson from '../package.json';
My tsconfig.json contains the following:
{
"compilerOptions": {
"...
80
votes
5
answers
31k
views
Build .exe file in .NET Core RC2
Every time I build a project using the new .NET Core RC2 templates I am not provided with a runnable .EXE file. If I hit F5 for debugging my console application it runs fine through the
C:\Program ...