在 xubuntu 上安装 yo 和 generator-code

在 xubuntu 上安装 yo 和 generator-code

因此,我一直在尝试为 xubuntu 安装 yo 和 generator-code,以尝试制作一些 vs 代码扩展,我通过 sudo apt-get 安装了 nodejs 和 npm,然后sudo npm install -g yo generator-code 当我尝试运行时yo -v or yo code出现以下错误

    filePatterns: lookups.flatMap(prefix => [`${prefix}/*/index.ts`, `${prefix}/*/index.js`, `${prefix}/*/index.cjs`, `${prefix}/*/index.mjs`]),
                          ^

TypeError: lookups.flatMap is not a function
    at Environment.resolver.lookup (/usr/local/lib/node_modules/yo/node_modules/yeoman-environment/lib/resolver.js:70:27)
    at init (/usr/local/lib/node_modules/yo/lib/cli.js:130:7)
    at pre (/usr/local/lib/node_modules/yo/lib/cli.js:89:3)
    at Object.<anonymous> (/usr/local/lib/node_modules/yo/lib/cli.js:219:3)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

后来我意识到 sudo 不是最好的方法,所以我为 npm-packages 创建了一个新目录,然后将前缀设置为它

mkdir "/programming/.npm-global"
npm config set prefix "/programming/.npm-global"
gedit ~/.profile

我补充说 export PATH=~/programming/.npm-global/bin:$PATH 然后我就这么做了

npm install -g yo generator-code

现在当我跑步时yo code我得到

/usr/local/lib/node_modules/yo/node_modules/yeoman-environment/lib/resolver.js:70
    filePatterns: lookups.flatMap(prefix => [`${prefix}/*/index.ts`, `${prefix}/*/index.js`, `${prefix}/*/index.cjs`, `${prefix}/*/index.mjs`]),
                          ^

TypeError: lookups.flatMap is not a function
    at Environment.resolver.lookup (/usr/local/lib/node_modules/yo/node_modules/yeoman-environment/lib/resolver.js:70:27)
    at init (/usr/local/lib/node_modules/yo/lib/cli.js:130:7)
    at pre (/usr/local/lib/node_modules/yo/lib/cli.js:89:3)
    at Object.<anonymous> (/usr/local/lib/node_modules/yo/lib/cli.js:219:3)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

如果我跑 sudo yo code

我明白了

/usr/local/lib/node_modules/yo/node_modules/conf/index.js:128
            throw err;
            ^

Error: EACCES: permission denied, open '/root/.config/insight-nodejs/insight-yo.json'
    at Object.openSync (fs.js:443:3)
    at Object.readFileSync (fs.js:343:35)
    at Conf.get store [as store] (/usr/local/lib/node_modules/yo/node_modules/conf/index.js:108:18)
    at Conf.get (/usr/local/lib/node_modules/yo/node_modules/conf/index.js:47:27)
    at Insight.get optOut [as optOut] (/usr/local/lib/node_modules/yo/node_modules/insight/lib/index.js:52:22)
    at Object.<anonymous> (/usr/local/lib/node_modules/yo/lib/cli.js:208:48)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

答案1

以下是我如何解决这个问题的方法我做了以下事情

npm remove yo

npm remove generator-code

sudo apt remove npm

sudo apt update

sudo apt install build-essential checkinstall libssl-dev

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.35.1/install.sh | bash

nvm install 16.11.0

npm config delete prefix

npm install -g npm

npm install yo generator-code

yo code

相关内容