I am having very strange issues with my npm packages and installs.
error Couldn't find package "@date-io/core" on the "npm" registry.
However installing with npm produces no errors, but I need to install via yarn for many project settings and scripts.
So, is it possible to view which .npmrc is being currently used in my project?
The .npmrc file. npm gets its config settings from the command line, environment variables, and npmrc files. The npm config command can be used to update and edit the contents of the user and global npmrc files. For a list of available configuration options, see npm-config(7). Files. The four relevant files are:
Running npm config ls -l will show you all the implicit settings for npm, including what it thinks is the right place to put the .npmrc, as this is environment/operating system dependant. But if you have never logged in (using npm login) it will be empty.
per-project config file (/path/to/my/project/.npmrc) All npm config files are an ini-formatted list of key = value parameters.
per-project config file (/path/to/my/project/.npmrc) All npm config files are an ini-formatted list of key = value parameters. Environment variables can be replaced using $ {VARIABLE_NAME}. For example: Each of these files is loaded, and config options are resolved in priority order.
"This edit might not make a whole lot of sense if you have not yet read the original answer below."
This answer will not work for Node.js versions earlier than
Node v14.0.0
(the solution works for:^14.0.0
). This was pointed out in the comments by @jonSakas who was insightful enough to know that the NPM CLI'spublish
command, when ran with the following flags,--dry-run --verbose
, as shown here:
npm publish --dry-run --verbose
...does not print the locations of the systems
.npmrc
files.
NPM configuration files can, and will, exist at different levels in any given environment where Node projects are being developed. As far as I know, there are three specific levels, and they are as follows:
npmrc
filenpmrc
file.npmrc
file. There are several was you can figure out where the .npmrc
file you are using is at, but you don't need to. For any project you have, stick a .npmrc file in the root directory, right next to ${rootDir}/node_modules/
and ${rootDir}/package.json
. The project-level .npmrc
will override any other NPM files that are altering your project. I have never had NPM alter a project though, unless I changed a configuration file, which meant I knew about the file and where it was. If for some reason though, you still need to find a .npmrc
, and changing the project level .npmrc
document will not help you, you probably don't want to use the raw version of npm config edit
, because that will just configure the project level npm document, and I think it will create one if there is not one, so its essentially does what at suggested at the beginning of the tangent I am on.
.npmrc
configuration file instead, like this...
npm config -g edit
You it just dawned on me, you actually have another way you can see what configuration files are active. I think this way shows you the file-paths that npm looks at to see if there is an NPM file there or not.
npm publish --dry-run --verbose
jayd3v@jayd3v-XPS-8910:~$ npm publish --dry-run --verbose
npm verb cli [
npm verb cli '/home/jayd3v/.nvm/versions/node/v17.6.0/bin/node',
npm verb cli '/home/jayd3v/.nvm/versions/node/v17.6.0/bin/npm',
npm verb cli 'publish',
npm verb cli '--dry-run',
npm verb cli '--verbose'
npm verb cli ]
npm info using [email protected]
npm info using [email protected]
npm timing npm:load:whichnode Completed in 1ms
npm timing config:load:defaults Completed in 1ms
npm timing config:load:file:/home/jayd3v/.nvm/versions/node/v17.6.0/lib/node_modules/npm/npmrc Completed in 0ms
npm timing config:load:builtin Completed in 1ms
npm timing config:load:cli Completed in 1ms
npm timing config:load:env Completed in 0ms
npm timing config:load:project Completed in 2ms
npm timing config:load:file:/home/jayd3v/.npmrc Completed in 1ms
npm timing config:load:user Completed in 1ms
npm timing config:load:file:/home/jayd3v/.nvm/versions/node/v17.6.0/etc/npmrc Completed in 0ms
npm timing config:load:global Completed in 0ms
npm timing config:load:validate Completed in 0ms
npm timing config:load:credentials Completed in 0ms
npm timing config:load:setEnvs Completed in 1ms
npm timing config:load Completed in 8ms
npm timing npm:load:configload Completed in 8ms
npm timing npm:load:setTitle Completed in 0ms
npm timing config:load:flatten Completed in 2ms
npm timing npm:load:display Completed in 6ms
npm verb logfile /home/jayd3v/.npm/_logs/2022-03-01T22_15_38_103Z-debug-0.log
npm timing npm:load:logFile Completed in 3ms
npm timing npm:load:timers Completed in 0ms
npm timing npm:load:configScope Completed in 0ms
npm timing npm:load Completed in 19ms
npm verb publish [ '.' ]
You can see that it showed me the three areas that it tried to pull a configuration file ('.npmrc') from. It even named which was which
npmrc
npm timing config:load:file:/home/jayd3v/.nvm/versions/node/v17.6.0/lib/node_modules/npm/npmrc Completed in 0ms
npm timing config:load:builtin Completed in 1ms
.npmrc
npm timing config:load:file:/home/jayd3v/.npmrc Completed in 1ms
npm timing config:load:user Completed in 1ms
npmrc
npm timing config:load:file:/home/jayd3v/.nvm/versions/node/v17.6.0/etc/npmrc Completed in 0ms
npm timing config:load:global Completed in 0ms
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With