-
-
Notifications
You must be signed in to change notification settings - Fork 790
Closed
Milestone
Description
Running the Quick Start with typescript defaults returns the following error when executed with tsc app.ts unless a tsconfig file is made and a handful of legacy compatibility features are turned on.
SyntaxError: The requested module '@feathersjs/koa' does not provide an export named 'bodyParser'
Reproduction: https://stackblitz.com/edit/node-lzf6x8?file=package.json,app.ts
Upon some debugging, body parser is not exported at top level... but in a property called default:
❯ tsx
Welcome to tsx v3.9.0 (Node.js v16.14.2).
Type ".help" for more information.
> import('@feathersjs/koa').then(console.log)
Promise { <unknown> }
> [Module: null prototype] {
default: {
Koa: [Getter],
bodyParser: [Getter],
koa: [Function: koa],
parseAuthentication: [Getter],
authenticate: [Getter],
errorHandler: [Getter],
formatter: [Getter],
rest: [Getter]
},
__esModule: true,
koa: [Function: koa],
authenticate: [Function: authenticate],
parseAuthentication: [Function: parseAuthentication],
errorHandler: [Function: errorHandler],
rest: [Function: rest],
formatter: [Function: formatter]
}
Proposed Solutions:
- Use tsup to automatically wrap the typescript modules for cjs and esm import.
- Drop support for CommonJs projects in new versions and only build for ES modules
Workarounds
- Using esno
- manually pick and hunt for dependencies within the CJS package
Additional Notes
- While TS 4.7 supports loading modules with Node natively, Vite does not. Support Typescript 4.7 "Node16" extension requirements vitejs/vite#8993 (comment)
- This causes problems when using build plugins as it's hard to get everyone to agree without support for Node's native behavior.
Metadata
Metadata
Assignees
Labels
No labels