以太坊的合约是通过特殊的 solidity 语言开发,solidity 是通过 remix 编译器开发,网上很多的文章都太老,或者是相互抄袭的,导致我在使用过程中各种报错,估计现在都已经 2021 年了吧。
错误方式
- 安装
npm install remix-ide -g
- 运行
remix-ide
internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module 'remixd'
Require stack:
- /usr/local/lib/node_modules/remix-ide/bin/remix-ide
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/usr/local/lib/node_modules/remix-ide/bin/remix-ide:4:14)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/usr/local/lib/node_modules/remix-ide/bin/remix-ide' ]
这里肯定会报错,找不到 remixd 模块。
- 那就
npm install -g remixd
npm WARN deprecated remixd@0.2.4: this package has been deprecated. Please use @remix-project/remixd
npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN ws@7.4.5 requires a peer of bufferutil@^4.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN ws@7.4.5 requires a peer of utf-8-validate@^5.0.2 but none is installed. You must install peer dependencies yourself.
npm ERR! code ENOENT
npm ERR! syscall chmod
npm ERR! path /usr/local/lib/node_modules/remixd/lib/bin/remixd.js
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, chmod '/usr/local/lib/node_modules/remixd/lib/bin/remixd.js'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/jake/.npm/_logs/2021-05-05T13_43_00_136Z-debug.log
这里一定还是会报错,于是我查看了npmjs.com 查了一下,remix 包已经移动到 @remix-project/remixd 下面
- 所以
npm uninstall -g remixd
卸载老版本 - 继续安装新版本
npm install -g @remix-project/remixd
这里成功了,但是 remix-ide
还是依然会报错,算了不想折腾这种方式了,还是使用 docker 吧
正确方式✅
-
docker run -p 18080:80 -d --name remix remixproject/remix-ide:latest
但是这里有个问题,是不能做文件映射,不能将宿主机和容器路径相关联,算了,先这样测试开发吧,后面再说。