Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERR_REQUIRE_ESM when running the usage example from repository's readme.md #102

Open
lkavicky opened this issue Jul 22, 2021 · 5 comments
Open

Comments

@lkavicky
Copy link

Describe the bug
When running the basic usage example from repository's readme, I'm getting following error:

internal/modules/cjs/loader.js:1085
      throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
      ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: D:\workspace\node-sspi-exp3\node_modules\node-fetch\src\index.js
require() of ES modules is not supported.
require() of D:\workspace\node-sspi-exp3\node_modules\node-fetch\src\index.js from D:\workspace\node-sspi-exp3\node_modules\node-expose-sspi\dist\sso\client.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 D:\workspace\node-sspi-exp3\node_modules\node-fetch\package.json.

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1085:13)
    at Module.load (internal/modules/cjs/loader.js:933:32)
    at Function.Module._load (internal/modules/cjs/loader.js:774:14)
    at Module.require (internal/modules/cjs/loader.js:957:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (D:\workspace\node-sspi-exp3\node_modules\node-expose-sspi\dist\sso\client.js:7:38)
    at Module._compile (internal/modules/cjs/loader.js:1068:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Module.load (internal/modules/cjs/loader.js:933:32)
    at Function.Module._load (internal/modules/cjs/loader.js:774:14) {
  code: 'ERR_REQUIRE_ESM'
}

To Reproduce

The same steps and flow as in readme:

mkdir myproject
cd myproject
npm init -y
npm i express
npm i node-expose-sspi
...
node server.js

server.js:

const express = require('express');
const { sso } = require('node-expose-sspi');

const app = express();
app.use(sso.auth());

app.use((req, res, next) => {
  res.json({
    sso: req.sso,
  });
});

app.listen(3000, () => console.log('Server started on port 3000'));

Expected behavior
Run without errors.

Environment version:

  • OS: Windows 10 Pro 10.0.19042 Build 19042 x64
  • Node version and architecture: v14.17.0 64bits
  • npm version: 6.14.13
@mishra-animesh
Copy link

I am also facing a similar issue.

@jlguenego
Copy link
Owner

Yes I am able to reproduce it.

It is probably because of the node-fetch library. The author released a new version which causes the issue.
Quick fix: npm i [email protected]

What I am going to do is to fix the node-fetch version.

@jlguenego
Copy link
Owner

It is fixed. Please test.

@mishra-animesh
Copy link

I tested and it works perfectly fine. Thanks a lot for quick turnaround :)

@lkavicky
Copy link
Author

It's working for me too, thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants