简体   繁体   English

全局安装节点 package 没有互联网服务器错误:没有这样的文件或目录

[英]Installing node package globally without internet on server error: No such file or directory

I'm working with a nodejs project.我正在使用 nodejs 项目。 The project has local and global dependency of npm packages.该项目具有 npm 包的本地和全局依赖关系。 The server where we want to deploy the project doesn't have the internet connection.我们要部署项目的服务器没有互联网连接。 So, we're trying to install npm packages on the server.因此,我们正在尝试在服务器上安装 npm 软件包。

For local dependency, copy local dependency from local machine to server works.对于本地依赖,将本地依赖从本地机器复制到服务器作品。 However, We are struggling to install global packages.但是,我们正在努力安装全局软件包。

We're using below global packages:我们正在使用以下全局包:

  1. Truffle v4.1.12.松露 v4.1.12。
  2. PM2 PM2

To install global packages we have tried several things like:要安装全局包,我们尝试了以下几种方法:

Copy executable to /user/local/bin from local machine and将可执行文件从本地机器复制到/user/local/bin
Copy content from lib/node_modules/truffle to /usr/local/lib/node_modules/truffle将内容从lib/node_modules/truffle复制到/usr/local/lib/node_modules/truffle

However, it didn't work.但是,它没有用。 Shows error as below even though the file cli.bundled.js is located.即使找到了文件cli.bundled.js ,也显示如下错误。

[redhat@redhat8 ~]$ truffle -v
/usr/local/bin/truffle: line 1: ../lib/node_modules/truffle/build/cli.bundled.js: No such file or directory

I thought it's issue of symbolic link so tried to create it我认为这是符号链接的问题,所以尝试创建它

ln -s /usr/local/bin/truffle /usr/local/lib/node_modules/truffle/build/cli.bundled.js

However still it's showing same error.但是它仍然显示相同的错误。 Is there anyway to make it work?有没有办法让它工作?

Instead of installing as a global module, which will require you to understand more about how your target system is configured, install it as a peer dependency.与其作为全局模块安装(这需要您更多地了解目标系统的配置方式),不如将其安装为对等依赖项。

npm install --save-peer pm2 truffle

This will place the executables in node_modules .这会将可执行文件放在node_modules中。 To invoke them, make sure you are in that directory with the package.json file.要调用它们,请确保您位于带有package.json文件的目录中。 (This is important to note for startup scripts and things like that, of course.) You can then invoke the executables with npx : (这对于启动脚本和类似的东西来说很重要,当然。)然后您可以使用npx调用可执行文件:

$ npx truffle -v
npx truffle -v   
Truffle v5.3.0 - a development framework for Ethereum

Usage: truffle <command> [options]

Commands:
  build     Execute build pipeline (if configuration present)
  compile   Compile contract source files
  config    Set user-level configuration options
  console   Run a console with contract abstractions and commands available
  create    Helper to create new contracts, migrations and tests
  db        Database interface commands
  debug     Interactively debug any transaction on the blockchain
  deploy    (alias for migrate)
  develop   Open a console with a local development blockchain
  exec      Execute a JS module within this Truffle environment
  help      List all commands or provide information about a specific command
  init      Initialize new and empty Ethereum project
  install   Install a package from the Ethereum Package Registry
  migrate   Run migrations to deploy contracts
  networks  Show addresses for deployed contracts on each network
  obtain    Fetch and cache a specified compiler
  opcode    Print the compiled opcodes for a given contract
  preserve  Save data to decentralized storage platforms like IPFS and Filecoin
  publish   Publish a package to the Ethereum Package Registry
  run       Run a third-party command
  test      Run JavaScript and Solidity tests
  unbox     Download a Truffle Box, a pre-built Truffle project
  version   Show version number and exit
  watch     Watch filesystem for changes and rebuild the project automatically

See more at http://trufflesuite.com/docs
$ 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM