npm 参考错误:全局未定义

weylhg0b  于 2022-11-24  发布在  其他
关注(0)|答案(2)|浏览(464)

我已经使用以下代码全局安装了npm模块aws-amplify/cli:

npm install -g @aws-amplify/cli

这是有效的,但当我尝试使用放大cli初始化我的环境时,它给我以下错误:

/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/queue-microtask/index.js:1
ReferenceError: globalThis is not defined
    at Object.<anonymous> (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/queue-microtask/index.js:5:25)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.<anonymous> (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/run-parallel/index.js:4:24)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.<anonymous> (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/@nodelib/fs.scandir/out/providers/async.js:5:13)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.<anonymous> (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/@nodelib/fs.scandir/out/index.js:4:15)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.<anonymous> (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/@nodelib/fs.walk/out/readers/async.js:4:19)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.<anonymous> (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/@nodelib/fs.walk/out/providers/async.js:3:17)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.<anonymous> (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/@nodelib/fs.walk/out/index.js:4:17)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.<anonymous> (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/fast-glob/out/readers/stream.js:5:16)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.<anonymous> (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/fast-glob/out/providers/async.js:3:18)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.<anonymous> (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/fast-glob/out/index.js:3:17)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.<anonymous> (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/globby/index.js:5:18)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.<anonymous> (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-category-function/lib/provider-utils/awscloudformation/utils/packageLayer.js:21:34)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.<anonymous> (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-category-function/lib/provider-utils/awscloudformation/utils/layerParams.js:13:24)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.<anonymous> (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-category-function/lib/provider-utils/awscloudformation/index.js:7:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.<anonymous> (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-category-function/lib/index.js:13:29)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Object.<anonymous> (/usr/local/lib/node_modules/@aws-amplify/cli/lib/extensions/amplify-helpers/update-amplify-meta.js:34:37)
    at Generator.next (<anonymous>)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at AmplifyToolkit.get updateamplifyMetaAfterResourceAdd [as updateamplifyMetaAfterResourceAdd] (/usr/local/lib/node_modules/@aws-amplify/cli/lib/domain/amplify-toolkit.js:229:17)
    at /usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-category-auth/lib/provider-utils/awscloudformation/utils/amplify-meta-updaters.js:48:21
    at processTicksAndRejections (internal/process/next_tick.js:81:5)

我该如何解决这个问题?

rekjcdws

rekjcdws1#

请考虑将node.js的版本更新为>=12
globalThis已根据此兼容性表添加到node.js v12.0.0中。

**注意:**另请参阅GitHub repo中的issue #17,了解报告此问题的queue-microtask

sg24os4d

sg24os4d2#

对我来说,通过更新pm2解决

npm install pm2 -g
pm2 update

相关问题