npm “gulp serve”返回“引用错误:未定义原始数字”

x759pob2  于 2022-11-14  发布在  Gulp
关注(0)|答案(2)|浏览(198)

今天是第一天与SPFx和Gulp和Yo等。
尝试使用教程,但出现以下错误:

mini-3:helloworld-webpart admin$ gulp serve
ReferenceError: primordials is not defined
    at fs.js:45:5
    at req_ (/playground/spfx/helloworld-webpart/node_modules/natives/index.js:143:24)
    at Object.req [as require] (/playground/spfx/helloworld-webpart/node_modules/natives/index.js:55:10)
    at Object.<anonymous> (/playground/spfx/helloworld-webpart/node_modules/vinyl-fs/node_modules/graceful-fs/fs.js:1:37)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:14)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object.<anonymous> (/playground/spfx/helloworld-webpart/node_modules/vinyl-fs/node_modules/graceful-fs/graceful-fs.js:3:27)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:14)
    at Module.require (internal/modules/cjs/loader.js:974:19)
About to exit with code: 1
Process terminated before summary could be written, possible error in async code not continuing!
Trying to exit with exit code 1

以下是我迄今为止采取的所有步骤:
https://pastebin.com/DC6XbPpq
正如你所看到的,当我尝试安装npm软件包时,我遇到了一堆错误,我不知道如何解决。另外...我尝试使用node的版本12和版本10。我不能安装/执行'yo'。我唯一能让yo工作的方法是使用node 14。
任何建议都将是有帮助的。我对节点,SPFx和npm非常陌生。如果我错过了一些简单的东西,我提前道歉。

编辑1

我不小心把东西弄到了工作上。我正在阅读关于gulp的书,试着只运行“gulp”而不运行“gulp serve”。这是我得到的:

mini-3:hello-new-world admin$ gulp
    Build target: DEBUG
    [14:31:45] Using gulpfile /playground/spfx/hello-new-world/gulpfile.js
    [14:31:45] Starting 'default'...
    [14:31:45] Starting gulp
    [14:31:45] Starting subtask 'configure-sp-build-rig'...
    [14:31:45] Finished subtask 'configure-sp-build-rig' after 2.53 ms
    [14:31:45] Starting subtask 'pre-copy'...
    [14:31:45] Finished subtask 'pre-copy' after 48 ms
    [14:31:45] Starting subtask 'copy-static-assets'...
    [14:31:45] Starting subtask 'sass'...
    [14:31:45] Finished subtask 'copy-static-assets' after 23 ms
    [14:31:45] Finished subtask 'sass' after 112 ms
    [14:31:45] Starting subtask 'tslint'...
    [14:31:45] [tslint] tslint version: 5.12.1
    [14:31:45] Starting subtask 'tsc'...
    [14:31:45] [tsc] typescript version: 3.7.7
    [14:31:47] Finished subtask 'tsc' after 1.74 s
    [14:31:47] Finished subtask 'tslint' after 2.3 s
    [14:31:47] Starting subtask 'post-copy'...
    [14:31:47] Finished subtask 'post-copy' after 105 μs
    [14:31:47] Starting subtask 'configure-webpack'...
    [14:31:47] Finished subtask 'configure-webpack' after 229 ms
    [14:31:47] Starting subtask 'webpack'...
    [14:31:48] Finished subtask 'webpack' after 673 ms
    [14:31:48] Finished 'default' after 3.38 s
    [14:31:49] ==================[ Finished ]==================
    [14:31:49] Project hello-new-world version:0.0.1
    [14:31:49] Build tools version:3.17.11
    [14:31:49] Node version:v14.17.3
    [14:31:49] Total duration:6.16 s

现在......大口发球也起作用了。
我不明白为什么。谁能解释一下?

avwztpqn

avwztpqn1#

Node 14在SPFx v1.12.1上运行良好。看起来您使用的是macOS...错误表明您没有安装XCode,特别是命令行工具(ref:“gyp:未检测到Xcode或CLT版本!")。简短的故事:它们包括一些软件包使用的编译器......当你安装NPM软件包时,有些软件包在安装后需要编译。它们会自动编译,所以对你来说是透明的,但是工具需要在那里。如果你在谷歌上搜索这个错误,你会发现很多关于如何修复它的点击,比如:https://medium.com/@mrjohnkilonzi/how-to-resolve-no-xcode-or-clt-version-detected-d0cf2b10a750
为什么第二次成功了而第一次不行......呃......无法解释这部分。可能是第一次构建失败了,但第二次尝试成功了。当运行gulp而没有指定要运行的任务时,它会使用默认的任务。我 * 认为 * 那是build任务......但gulp serve无论如何都会运行build任务。
我仍然会修复缺少的XCode CLI工具...这不仅仅是SPFx的事情,而是您将来使用的任何依赖于NPM包的东西,它们都将需要它。

  • 顺便说一句,在未来,如果你说你使用的是什么版本的SPFx,它会有所帮助。在这种情况下,你可以从pastebin推断出它是v1.12.1,但这是一个关键的第一个问题。*
zujrkrfu

zujrkrfu2#

您需要安装正确的gulp版本,该版本已更新为您的npm版本。要更新npm,请运行:

npm install

然后指定大口版本,示例:

npm install gulp@^4.0.2

相关问题