Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors when searching for libs #44

Open
htaunay opened this issue May 18, 2015 · 3 comments
Open

Errors when searching for libs #44

htaunay opened this issue May 18, 2015 · 3 comments

Comments

@htaunay
Copy link

htaunay commented May 18, 2015

I am interested in customising my 'npm init' process (e.g. defining different default values or adding new settings to the generated 'package.json') and was under the impression that this could be done by adding a '~/.npm-init.js' file with contents similar as to the one described in the 'README.md' of the 'init-package-json' project.

However, I am stumbling upon what I believe are some path/configuration issues, mainly consisting of 'node_modules' not being found, despite the necessary dependencies being available in the global 'node_modules' dir.

Here is a simple example:

[myuser ~/test]$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sane defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
npm ERR! Linux 2.6.32-504.8.1.el6.centos.plus.x86_64
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "init"
npm ERR! node v0.12.0
npm ERR! npm  v2.5.1
npm ERR! code MODULE_NOT_FOUND

npm ERR! Cannot find module 'glob'
npm ERR! 
npm ERR! If you need help, you may report this error at:
npm ERR!     <http://github.com/npm/npm/issues>
About to write to /home/myuser/test/package.json:

{
  "name": "",
  "version": ""
}


Is this ok? (yes) no
Aborted.

As already stated, glob is already globally available (installed with -g).
Now, if I try to explicitly set the node path, I get errors regarding other libs not available globally:

[myuser ~/test]$ NODE_PATH=/usr/lib/node_modules npm init

npm ERR! code MODULE_NOT_FOUND
npm ERR! Cannot find module 'validate-npm-package-name'

I could globally install the other necessary packages... but I feel that I may be tackling this problem the wrong way, and that manually specifying the node path plus manually installing dependencies seems like overkill. Am I missing some step/configuration that should allow the '~/.node-init.js' integration work more seamlessly?

@michaelnisi
Copy link
Contributor

What do you want to put in your package file that cannot be set with npm config? Sorry for not being of any help.

@htaunay
Copy link
Author

htaunay commented May 22, 2015

Thanks for the reply! In fact npm configworks fine for some parameters (e.g. version and license), but I am interested in also defining some other initial configuration in the generated package.json, such as default startand test scripts.

I was under the impression that through init-package-json's init function I would be able to make such customisations. Maybe I misunderstood the purpose of the module?

@brettz9
Copy link

brettz9 commented Feb 4, 2021

.npm-init.js is not living up to what I thought it was supposed to be. (and npm referring us here isn't too helpful as the API doesn't seem to match the format expected by .npm-init.js.

A few problems so far:

  1. use strict caused a crash
  2. I did discover from the README that basename, filename, and dirname (as well as prompt) were predefined, but didn't end up needing require('path').basename, so not too big of an issue for me, and one can rename.
  3. I wanted to preconfigure a choice of type, scripts, devDependencies, etc. based on whether the user were using modules or not, yet I can't get this prompt to work: const modules = prompt('Module? (leave blank to be CommonJS)', 'y'); It seems prompt only works if being assigned to a variable like description or one of the recognized export names, but I figured, I should be able to name variables as I wished within the file until setting on exports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants