You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hitting server restart will not clear node_modules, for that do rm -rf, then hit server restart
The IDE is running TS 4.1.2... ignore the UI, package.json is using TS 4.5-beta
If you run this on your machine, make sure to use ts-node 10.4.0, as it has support for loader API changes made between Node 16.8-16.12
Changes needed:
Like deno, importing modules needs to be unambiguous. But as node doesn't natively support ts, the extension still needs to be .js
Instead of ./middleware you import ./middleware/index.js
Instead of ./channels you import ./channels.js
A number of feathers modules have index.d.ts implicitly loaded, those need to be explicit
Some of the module typescript relies on ESM compatibility layers between TS pseudo-ESM and CommonJS. Those stop working when running TS backed by native Node ESM.
'@feathersjs/configuration' mixes default exports with named exports, which cause it's CommonJS default export to be exposed under a .default property.
If we can re export configuration under default, the CJS and ESM Typescript would check out.
Winston has no named exports for ESM
Node's path module has no default export under ESM...
Change import path from 'path' to import { join } from path, or use * as path
feathers-nedb has a broken devDependency, nedb. I added an ambient type and removed the user.class.ts reference to hide the issue.
path has no default import under ESM
I've included a shell script to handle node_modules TS issues in the meantime.
# The main property changes aren't strictly necessary but highly advised by the TS handbook
sed -i '6s/"main": "lib\/",/"main": "\.\/lib\/index\.js",/' ./node_modules/\@feathersjs/configuration/package.json
sed -i '7s/"types": "lib\/",/"types": "\.\/lib\/index\.d\.ts",/' ./node_modules/\@feathersjs/configuration/package.json
sed -i '6s/"main": "lib\/",/"main": "\.\/lib\/index\.js",/' ./node_modules/\@feathersjs/authentication/package.json
sed -i '7s/"types": "lib\/",/"types": "\.\/lib\/index\.d\.ts",/' ./node_modules/\@feathersjs/authentication/package.json
sed -i '6s/"main": "lib\/",/"main": "\.\/lib\/index\.js",/' ./node_modules/\@feathersjs/authentication-local/package.json
sed -i '7s/"types": "lib\/",/"types": "\.\/lib\/index\.d\.ts",/' ./node_modules/\@feathersjs/authentication-local/package.json
sed -i '6s/"main": "lib\/",/"main": "\.\/lib\/index\.js",/' ./node_modules/\@feathersjs/authentication-oauth/package.json
sed -i '7s/"types": "lib\/",/"types": "\.\/lib\/index\.d\.ts",/' ./node_modules/\@feathersjs/authentication-oauth/package.json
# unfixably bad types... needs generics
sed -i '6s/"main": "lib\/",/"main": "\.\/lib\/index\.js",/' ./node_modules/feathers-nedb/package.json
# sed -i '7s/"types": "types",/"types": "\.\/types\/index\.d\.ts",/' ./node_modules/feathers-nedb/package.json
sed -i '2s/import express/import \* as express/' ./node_modules/\@feathersjs/express/index.d.ts
sed -i '1s/import http/import \* as http/' ./node_modules/\@feathersjs/socketio/index.d.ts
sed -i '2s/import io/import \* as io/' ./node_modules/\@feathersjs/socketio/index.d.ts
sed -i '8s/"source",/"\.\/source\/index\.js",\n"types": "\.\/index\.d\.ts",/' ./node_modules/chalk/package.json
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
rm -rf
, then hit server restartChanges needed:
./middleware
you import./middleware/index.js
./channels
you import./channels.js
.default
property.default
, the CJS and ESM Typescript would check out.import path from 'path'
toimport { join } from path
, or use* as path
I've included a shell script to handle node_modules TS issues in the meantime.
Beta Was this translation helpful? Give feedback.
All reactions