2

I created an API in nodeJS and im use IISnode to publish it.

If I start the application in vcode with "npm start" it runs perfectly.

If I start the application in iisnode, I get following error:

Application has thrown an uncaught exception and is terminated: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\inetpub\wwwroot\index.js require() of ES modules is not supported. require() of C:\inetpub\wwwroot\index.js from C:\Program Files\iisnode\interceptor.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules. Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\inetpub\wwwroot\package.json.
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1080:13)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (C:\Program Files\iisnode\interceptor.js:210:1)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)

'Type: module' is included in my package.json

Can someone help out here?

deca
  • 51
  • 5
  • Make sure that IISnode is installed correctly, and then try to republish your application, here is the referecne of installing iisnode: https://harveywilliams.net/blog/installing-iisnode – Theobald Du Apr 09 '21 at 09:49
  • The workaround described here seems to work: https://github.com/Azure/iisnode/issues/90 – tverilytt Jul 09 '21 at 12:12

0 Answers0