feathersjs / feathers

The API and real-time application framework
https://feathersjs.com
MIT License
14.98k stars 743 forks source link

The requested module './authentication.js' does not provide an export named 'authentication' #3228

Closed lucaspmarra closed 9 months ago

lucaspmarra commented 1 year ago

Running project AS-IS, following documentation ends with a error

Doc page: https://feathersjs.com/cookbook/authentication/firebase.html

firebase.js and authentication.js is like doc says and the error explode:

import { authentication } from './authentication.js' ^^^^^^^^^^^^^^ SyntaxError: The requested module './authentication.js' does not provide an export named 'authentication'

I've tried another approach in authentication.js:

import { AuthenticationService, JWTStrategy } from '@feathersjs/authentication'
import { LocalStrategy } from '@feathersjs/authentication-local'
import { oauth, OAuthStrategy } from '@feathersjs/authentication-oauth'

const { FirebaseStrategy } = require('./firebase');

export const authentication = (app) => {
  const authentication = new AuthenticationService(app)

  authentication.register('jwt', new JWTStrategy())
  authentication.register('local', new LocalStrategy())
  authentication.register('auth0', new OAuthStrategy())
  authentication.register('firebase', new FirebaseStrategy());

  app.use('authentication', authentication)
  app.configure(oauth())
}

Got the error as expected:

const { FirebaseStrategy } = require('./firebase');
                             ^
ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and 'E:\Documents\Github\feathers-adoption-api\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.

Changed authentication.js:

import { AuthenticationService, JWTStrategy } from '@feathersjs/authentication'
import { LocalStrategy } from '@feathersjs/authentication-local'
import { oauth, OAuthStrategy } from '@feathersjs/authentication-oauth'
import { FirebaseStrategy } from './firebase';

export const authentication = (app) => {
  const authentication = new AuthenticationService(app)

  authentication.register('jwt', new JWTStrategy())
  authentication.register('local', new LocalStrategy())
  authentication.register('auth0', new OAuthStrategy())
  authentication.register('firebase', new FirebaseStrategy());

  app.use('authentication', authentication)
  app.configure(oauth())
}

New error:

    ErrorCaptureStackTrace(err);
    ^
Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'E:\Documents\Github\feathers-adoption-api\src\firebase' imported from E:\Documents\Github\feathers-adoption-api\src\authentication.js

If doc is not working, what should I do?