node.js - Installing node package globally without internet on server error: No such file or directory
问题描述
I'm working with a nodejs project. The project has local and global dependency of npm packages. 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.
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:
- Truffle v4.1.12.
- PM2
To install global packages we have tried several things like:
Copy executable to /user/local/bin
from local machine and
Copy content from lib/node_modules/truffle
to /usr/local/lib/node_modules/truffle
However, it didn't work. Shows error as below even though the file cli.bundled.js
is located.
[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?
解决方案
与其作为全局模块安装(这需要您更多地了解目标系统的配置方式),不如将其安装为对等依赖项。
npm install --save-peer pm2 truffle
这会将可执行文件放在node_modules
. 要调用它们,请确保您位于该package.json
文件所在的目录中。(这对于启动脚本和类似的东西来说很重要,当然。)然后您可以使用以下命令调用可执行文件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
$
推荐阅读
- python - Python SQLite - 更新未运行
- typescript - 加载器的 Webpack 4 语法
- groovy - Groovy 中的 int 类型 > 运算符错误
- wordpress - Wordpress 简码标签,怎么了?
- html - 如何使用 :before 和 :after 伪元素
- javascript - 为什么我在挂载的钩子中出现错误:“TypeError:e 未定义”?
- ruby-on-rails - 如何从Angular App中删除#?
- php - 使用 3 个不同的表更新第 4 个表
- ios - 如何在没有任何第三方库的情况下使用钥匙串在swift 4中存储敏感数据
- python-2.7 - AttributeError:GaussianMixture 实例没有属性“loglike”