0

I have the following versions on my machine:

+-- @microsoft/generator-sharepoint@1.4.1
+-- gulp@3.9.1
+-- typescript@2.4.0
`-- yo@3.1.1

Scaffolding in Yeoman, I have selected the option SharePoint 2016 onwards. When I run gulp serve I get the following:

 Error: Cannot find module 'typescript'
at Function.Module._resolveFilename (module.js:536:15)
at Function.Module._load (module.js:466:25)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\Users\dchiev\node_modules\tslint\lib\linter.js:20:10)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3) code: 'MODULE_NOT_FOUND' } [11:21:06] Error - Unknown  Cannot find module

'typescript' [11:21:07] ==================[ Finished ]================== [11:21:07] Project helloworld version: 0.0.1 [11:21:07] Build tools version: 2.5.3 [11:21:07] Node version: v8.9.0 [11:21:07] Total duration: 3.97 s [11:21:07] Task errors: 2

Any help would be great!

2
1

I've been doing some SPFx for SP 2016, and what I have that works is:

Node v8.17.0

then the only things I have installed globally are:

@microsoft/generator-sharepoint@1.13.0  // i think this is the latest?
gulp-cli@1.2.2
npm@6.13.4
yo@3.1.1

Then after scaffolding out the project, the generator added gulp@3.9.1 as a dev dependency. I don't see typescript referenced anywhere, but I do see it in my node_modules.

Oh, and I definitely do not use the --skip-install flag when running yo @microsoft/sharepoint, I let it do it's thing and manage the full install of everything it needs.


To address Denis Molodtsov's comment:

I hear what you are saying but I am telling you for a fact that the versions I listed above do work to create a SPFx web part for SP 2016 (I've made a few so far).

I spent the better part of a day testing different combinations of different versions of the tools to see what works, and that's what I ended up with.

I can't speak on SP 2019 / SPFx v.1.4.1 because I haven't needed to make any web parts for 2019 yet so I haven't gone through the drill of figuring out the right combination of the highest versions of things that work, but I would think that if this version combination works for 2016, it would also probably work for 2019.

Yes it's true that the version of SPFx that is supported on 2016 is v1.1, but you can use the most recent generator to scaffold out the project, as long as you are selecting the option to create a web part for 2016. I can see in my package.json that the SPFx packages scaffolded (sp-core-library, sp-webpart-base, etc) are indeed version 1.1.

As far as the compatibility matrix you linked to, I know that that says that you should use Node v.6 for SPFx v1.1, but because of the issue discussed here:

Around this the time of the v1.1 release, Node.js was transitioning from Node.js v6.x to v8.x. In this update, Node.js introduced a change where the default HTTP protocol switched from HTTP1 to HTTP2. SPFx v1.1 was written for HTTP1, not HTTP2, so this change affected the local web server for SPFx v1.1 projects.

In Node.js v8.x, you can force HTTP1 by setting the following environment variable to instruct Node.js to use HTTP1 instead of the default HTTP2: NODE_NO_HTTP2=1. This environment variable only exists in Node.js v8.x. That's why if you're building SPFx solutions for SharePoint Server 2016, you should use Node.js v8.x.

So even though the compatibility matrix says use Node v.6, you actually have to use Node v.8 so you're able to set that environment variable.

I even change my npm script in package.json to be:

"dev": "set NODE_NO_HTTP2=1&& gulp serve"

As an additional aside, I have found that you can't use yarn as your package manager for this setup because yarn does some additional version/compatibility checking which will prevent you from adding other dependencies into your project, so you have to stick with npm only.

3
  • Hi @Dylan. I think, SPFx is very particular about versions of node, npm, etc. For example, SP 2016 only supports SPFx 1.1 generator. Versions of node and npm are also supposed to be lower: docs.microsoft.com/en-us/sharepoint/dev/spfx/compatibility Nov 25 at 4:05
  • 1
    @DenisMolodtsov, updated my answer to address your comment. Nov 26 at 20:53
  • wow, great research. Thank you. I didn't know I can use a new generator for SP2016/2019. I also remember the HTTP-related issue a few years ago. looks like the official compatibility matrix needs more updates. Nov 27 at 0:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.