spfx-fast-serve icon indicating copy to clipboard operation
spfx-fast-serve copied to clipboard

npx fast-serve config add throws error

Open SPFxAppDev opened this issue 10 months ago • 10 comments

Hi,

I am using SPFx 1.18.2 with the latest spfx-fast-serve package (and spfx-fast-serve-helpers v1.18). I also use Node 18 and pnpm as package manager.

When I run this command:

npx fast-serve config add

I get this error:

node:internal/modules/cjs/loader:1140
  const err = new Error(message);
              ^

Error: Cannot find module 'D:\Projects\MyProj\news\fast-serve\config.json'
Require stack:
- D:\Projects\MyProj\news\node_modules\.pnpm\[email protected]_@[email protected][email protected][email protected]\node_modules\spfx-fast-serve-helpers\lib\webpack\helpers.js
- D:\Projects\MyProj\news\node_modules\.pnpm\[email protected]_@[email protected][email protected][email protected]\node_modules\spfx-fast-serve-helpers\lib\webpack\configureWebPack.js
- D:\Projects\MyProj\news\node_modules\.pnpm\[email protected]_@[email protected][email protected][email protected]\node_modules\spfx-fast-serve-helpers\lib\webpack\devServer.js
- D:\Projects\MyProj\news\node_modules\.pnpm\[email protected]_@[email protected][email protected][email protected]\node_modules\spfx-fast-serve-helpers\lib\serve.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1140:15)
    at Module._load (node:internal/modules/cjs/loader:981:27)
    at Module.require (node:internal/modules/cjs/loader:1231:19)
    at require (node:internal/modules/helpers:177:18)
    at Object.getJSONFile (D:\Projects\MyProj\news\node_modules\.pnpm\[email protected]_@[email protected][email protected][email protected]\node_modules\spfx-fast-serve-helpers\lib\webpack\helpers.js:42:12)
    at D:\Projects\MyProj\news\node_modules\.pnpm\[email protected]_@[email protected][email protected][email protected]\node_modules\spfx-fast-serve-helpers\lib\webpack\configureWebPack.js:49:36
    at Generator.next (<anonymous>)
    at D:\Projects\MyProj\news\node_modules\.pnpm\[email protected]_@[email protected][email protected][email protected]\node_modules\spfx-fast-serve-helpers\lib\webpack\configureWebPack.js:27:71
    at new Promise (<anonymous>)
    at __awaiter (D:\Projects\MyProj\news\node_modules\.pnpm\[email protected]_@[email protected][email protected][email protected]\node_modules\spfx-fast-serve-helpers\lib\webpack\configureWebPack.js:23:12)
    at createConfig (D:\Projects\MyProj\news\node_modules\.pnpm\[email protected]_@[email protected][email protected][email protected]\node_modules\spfx-fast-serve-helpers\lib\webpack\configureWebPack.js:47:12)
    at D:\Projects\MyProj\news\node_modules\.pnpm\[email protected]_@[email protected][email protected][email protected]\node_modules\spfx-fast-serve-helpers\lib\webpack\configureWebPack.js:101:128
    at Generator.next (<anonymous>)
    at D:\Projects\MyProj\news\node_modules\.pnpm\[email protected]_@[email protected][email protected][email protected]\node_modules\spfx-fast-serve-helpers\lib\webpack\configureWebPack.js:27:71
    at new Promise (<anonymous>)
    at __awaiter (D:\Projects\MyProj\news\node_modules\.pnpm\[email protected]_@[email protected][email protected][email protected]\node_modules\spfx-fast-serve-helpers\lib\webpack\configureWebPack.js:23:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'D:\\Projects\\MyProj\\news\\node_modules\\.pnpm\\[email protected]_@[email protected][email protected][email protected]\\node_modules\\spfx-fast-serve-helpers\\lib\\webpack\\helpers.js',
    'D:\\Projects\\MyProj\\news\\node_modules\\.pnpm\\[email protected]_@[email protected][email protected][email protected]\\node_modules\\spfx-fast-serve-helpers\\lib\\webpack\\configureWebPack.js',
    'D:\\Projects\\MyProj\\news\\node_modules\\.pnpm\\[email protected]_@[email protected][email protected][email protected]\\node_modules\\spfx-fast-serve-helpers\\lib\\webpack\\devServer.js',
    'D:\\Projects\\MyProj\\news\\node_modules\\.pnpm\\[email protected]_@[email protected][email protected][email protected]\\node_modules\\spfx-fast-serve-helpers\\lib\\serve.js'
  ]
}

Node.js v18.20.2

What am I doing wrong? The error confuses me a bit, because I think the command should create this file, but the error means that the file does not exist. Of course it is not there, because the command should create it :-D

SPFxAppDev avatar Apr 12 '24 12:04 SPFxAppDev

Seems your \spfx-fast-serve-helpers is not the latest, because in the stack trace it says [email protected], but should be 1.18.12

s-KaiNet avatar Apr 12 '24 13:04 s-KaiNet

Hmmm, okay, I'll try, but the dependencies are installed automatically, right? I selected "yes/enter" when the spfx-fast-serve command asked me if I wanted to install the dependencies ....

(spfx-fast-serve Version 4.0.1)

EDIT:

After I manually updated the spfx-fast-serve-helpers package to version 1.18.12, it works

SPFxAppDev avatar Apr 12 '24 13:04 SPFxAppDev

Hmmm, okay, I'll try, but the dependencies are installed automatically, right? I selected "yes/enter" when the spfx-fast-serve command asked me if I wanted to install the dependencies ....

Yep, as soon as you have tilde ~1.18.0, the latest patch version should be installed, I've just tested with pnpm and it worked for me. Curious how 1.18.0 installed for you.

s-KaiNet avatar Apr 12 '24 13:04 s-KaiNet

Yes, I know, the tilde installs the latest patch version. That's strange! I will keep an eye on this problem. Maybe it was just a "one in a million" case :D

I will close the issue, thanks for the quick help!

SPFxAppDev avatar Apr 12 '24 13:04 SPFxAppDev

Hmmm, it's happening again with a new project. I don't know why. I use pnpm as package manager and it has installed version 1.18.0 again

SPFxAppDev avatar Apr 19 '24 11:04 SPFxAppDev

If you have fast-serve listed in package.json with tilde, and if you remove pnpm's lock file and install dependencies, what version will be actually installed for you? (Assuming that you have ~1.18.0 in package.json)

s-KaiNet avatar Apr 19 '24 12:04 s-KaiNet

Yes, it was ~1.18.0 ==> After I installed pnpm i spfx-fast-serve-helpers@latest, it is now "spfx-fast-serve-helpers": "~1.18.12"

I deleted the pnpm-lock.yaml and uninstalled the package spfx-fast-serve-helpers and added "spfx-fast-serve-helpers": "~1.18.0" in the package.json again. Then I executed the pnpm i command ==> Result: the version 1.18.0 was installed...

SPFxAppDev avatar Apr 19 '24 13:04 SPFxAppDev

Which pnpm version do you use? Does it happen on windows, WSL, or OSX?

s-KaiNet avatar Apr 19 '24 13:04 s-KaiNet

I use pnpm Version 8.6.5 with Node 16 on Windows

SPFxAppDev avatar Apr 19 '24 13:04 SPFxAppDev

Strange enough, but when I tried with pnpm 8.6.5 I was able to reproduce the issue, but not with 8.15.7 (latest 8.x). For me, it looks like pnpm bug? Also works with pnpm 9.x. Could you update pnpm and see if it resolves the issue?

s-KaiNet avatar Apr 22 '24 22:04 s-KaiNet

This issue has been automatically closed because we haven't received any response back. Please feel free to reopen if needed.

github-actions[bot] avatar May 12 '24 00:05 github-actions[bot]

Hi, sorry for the late reply. The PNPM update has solved the problem. Thank you

SPFxAppDev avatar May 21 '24 13:05 SPFxAppDev