Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

TypeScript compilation error after adding the first service - service x.validate has not exported member 'create' #37

Closed
ewildee opened this issue Sep 7, 2018 · 7 comments

Comments

@ewildee
Copy link

ewildee commented Sep 7, 2018

Steps to reproduce

  • Create a configuration with feathers-plus generate options selecting TypeScript and semicolon enabled
  • Generate the app with feathers-plus generate app, all options to default
  • Start the empty application (this works): npm start
  • Stop the application
  • Add a new service called 'messages' with feathers-plus generate service, all options to default
  • Start the application with npm start and the TypeScript compilation error is shown

Expected behavior

I expected that Feathers was started without any problems

Actual behavior

An TypeScript compilation error occurred:

TSError: ⨯ Unable to compile TypeScript:
src/services/messages/messages.hooks.ts(11,10): error TS2305: Module '"[full path]/src/services/messages/messages.validate"' has no exported member 'create'.
src/services/messages/messages.hooks.ts(11,18): error TS2305: Module '"/[full path]/src/services/messages/messages.validate"' has no exported member 'update'.
src/services/messages/messages.hooks.ts(11,26): error TS2305: Module '"[full path]/src/services/messages/messages.validate"' has no exported member 'patch'.
src/services/messages/messages.hooks.ts(11,33): error TS2305: Module '"[full path]/src/services/messages/messages.validate"' has no exported member 'validateCreate'.
src/services/messages/messages.hooks.ts(11,49): error TS2305: Module '"/[full path]/src/services/messages/messages.validate"' has no exported member 'validateUpdate'.
src/services/messages/messages.hooks.ts(11,65): error TS2305: Module '"[full path]/src/services/messages/messages.validate"' has no exported member 'validatePatch'.

After commenting out the import { create, update, patch, validateCreate, validateUpdate, validatePatch } from './messages.validate'; line in messages.hooks.ts, the application starts without any problems.

System configuration

Tell us about the applicable parts of your setup.

Module versions (especially the part that's not working):

"dependencies": {
    "@feathersjs/authentication": "^2.1.7",
    "@feathersjs/authentication-jwt": "^2.0.1",
    "@feathersjs/authentication-local": "^1.2.1",
    "@feathersjs/configuration": "^2.0.2",
    "@feathersjs/errors": "^3.3.2",
    "@feathersjs/express": "^1.2.5",
    "@feathersjs/feathers": "^3.2.1",
    "@feathersjs/socketio": "^3.2.4",
    "ajv": "^5.5.2",
    "compression": "^1.7.3",
    "cors": "^2.8.4",
    "feathers-hooks-common": "^4.16.3",
    "feathers-nedb": "^3.1.0",
    "helmet": "^3.13.0",
    "lodash.merge": "^4.6.1",
    "nedb": "^1.8.0",
    "serve-favicon": "^2.5.0",
    "winston": "^3.0.0"
  },
  "devDependencies": {
    "@types/compression": "0.0.36",
    "@types/cors": "^2.8.4",
    "@types/feathersjs__authentication": "^2.1.1",
    "@types/feathersjs__authentication-jwt": "^1.0.3",
    "@types/feathersjs__authentication-local": "^1.0.2",
    "@types/feathersjs__configuration": "^1.0.1",
    "@types/feathersjs__errors": "^3.2.1",
    "@types/feathersjs__express": "^1.1.4",
    "@types/feathersjs__feathers": "^3.0.4",
    "@types/feathersjs__socketio": "^3.0.3",
    "@types/helmet": "0.0.40",
    "@types/lodash.merge": "^4.6.4",
    "@types/mocha": "^5.2.5",
    "@types/nedb": "^1.8.5",
    "@types/request-promise": "^4.1.42",
    "@types/serve-favicon": "^2.2.30",
    "@types/winston": "^2.4.4",
    "eslint": "^5.5.0",
    "mocha": "^5.2.0",
    "request": "^2.88.0",
    "request-promise": "^4.2.2",
    "ts-mocha": "^2.0.0",
    "ts-node": "^7.0.1",
    "ts-node-dev": "^1.0.0-pre.28",
    "tslint": "^5.11.0",
    "typescript": "^3.0.3"
  }

NodeJS version: v8.11.2

Operating System: macOS 10.13.5

Browser Version:

React Native Version:

Module Loader: TypeScript 3.0.3 with ts-node 7.0.1

@eddyystop
Copy link
Member

Darn. Thanks for pointing this out.

j2L3e: I added the import from serviceName.validate.?s recently. Nothing refers to the "imported" values. It works for JS but not for TS.

f+/cli has been updated to generate that line commented out. We'll fix it in the next day or two.

Published as f+/cli v0.7.21 using generator v0.6.20.

@j2L4e
Copy link
Member

j2L4e commented Sep 8, 2018

The issue is TypeScript's export default being compiled to module.exports.default =.
A ts default export can't be destructured in the import directly.
Keeping the exports unchanged this would work:
import validate from 'service.validate.ts' and then destructure with const {...} = validate;

@j2L4e
Copy link
Member

j2L4e commented Sep 8, 2018

The TS way would be named exports, but that would need a lot more changes

@eddyystop
Copy link
Member

I would go for the named exports but for backward compatibility. I assume we can go with

export default moduleExports;
export const create;
...
export function validateCreate;
...

which, although ugly, provides backward compatibility and lets TS use the import { ... } from syntax?

@eddyystop
Copy link
Member

j2L4e's suggestion published as f+/cli v0.7.22 using generator v0.6.21.

@ewildee
Copy link
Author

ewildee commented Sep 10, 2018

Thanks for solving this issue so quickly!

I solved the problem myself by exporting the moduleExports object directly like export { create, .., quickValidate }, but this doesn't give backward compatibility in js.

(I don't know if reopening this ticket is appropriate, but I appreciate your tools very much and would like to thank you)

@eddyystop
Copy link
Member

Thanks are always very appreciated.

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

No branches or pull requests

3 participants