Root directory in package.json

前端 未结 7 1678
臣服心动
臣服心动 2020-12-25 10:25

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 syste

7条回答
  •  太阳男子
    2020-12-25 11:07

    package.json is mainly a file used by npm to install and manage dependencies.

    the require construct does not care a lot about package.json so you will not be able to use it to subvert the way require works and make it believe that packages are not where the require loading scheme expects them.

    See the documentation on https://nodejs.org/api/modules.html and the loading scheme here: https://nodejs.org/api/modules.html#modules_all_together

    you could maybe use the technique that the documentation calls 'Loading from the global folders' and define the NODE_PATH environment variable.

    but I advise you to stick to a more standard way : - put your modules in a node_modules directory - or start your module hierarchy in the same directory where your app.js or index.js is located

提交回复
热议问题