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

[Bug]: Cannot use @octokit/auth-oauth-user in BFF mode. #6577

Closed
veaba opened this issue Nov 27, 2024 · 1 comment
Closed

[Bug]: Cannot use @octokit/auth-oauth-user in BFF mode. #6577

veaba opened this issue Nov 27, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@veaba
Copy link

veaba commented Nov 27, 2024

Version

modern.js `2.62.1`

Details

In BFF mode, where the api directory is at the root level, using @octokit/auth-oauth-user gets a TypeError error.

TypeError: Unknown file extension ".ts" for F:\Github\xx\xx\api\lambda\redirect\auth.ts
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:160:9)
    at defaultGetFormat (node:internal/modules/esm/get_format:203:36)
    at defaultLoad (node:internal/modules/esm/load:143:22)
    at async ModuleLoader.load (node:internal/modules/esm/loader:553:7)
    at async ModuleLoader.moduleProvider (node:internal/modules/esm/loader:434:45)
    at async link (node:internal/modules/esm/module_job:87:21) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
error   TypeError: Cannot destructure property 'module' of 'moduleInfo' as it is null.

Reproduce link

https://github.com/veaba/error-projects-list

Reproduce Steps

cd modern-bff-module-error
pnpm install
pnpm run dev
@veaba veaba added the bug Something isn't working label Nov 27, 2024
@yimingjfe
Copy link
Member

yimingjfe commented Dec 5, 2024

Since this package is a pure esm package and we recommend using dual package as much as possible. Modern.js server runs in commonjs format by default and has basic support for esm projects, so if you want to use this package directly, you'll need to transform the project to esm:

  1. Specify the type field as module in the package.json of the project:
{
  "name": "modern-app",
  "type": "module"
}
  1. Modify tsconfig.json
{
  "module": "esnext",
  "moduleResolution": "Bundler"
}
  1. Add the suffix .js
    If the code in the server, api, shared directories in the project is imported by a relative path, the .js suffix needs to be added after the file name, for example:
import type { Vars } from '../shared/index.js';

const setPayload: UnstableMiddleware<Vars> = async (
  c: UnstableMiddlewareContext<Vars>,
  next,
) => {
  c.set('message', 'message');
  await next();
};

export const unstableMiddleware: UnstableMiddleware<Vars>[] = [setPayload];

Note that you can't use tsconfig paths in the server, api, shared directories, which are not currently supported with esm.

@veaba veaba closed this as completed Dec 12, 2024
@yimingjfe yimingjfe self-assigned this Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants