midwayjs / midway-serverless-examples

MIT License
36 stars 15 forks source link

修改APIService 注入ctx 报错 'ctx' has no initialize #5

Closed AviorAlong closed 4 years ago

AviorAlong commented 4 years ago
@Inject()
  ctx: FaaSContext;

  @Func('api.render', { middleware: [ 'fmw:staticFile' ]})
  async render() {
    return 'Building... Please refresh this page later.';
  }

node v10.15.3 npm run build 报错:

ERROR in D:/selfProject/faas/faas-test/imageHandle/src/apis/index.ts(9,3): 9:3 Property 'ctx' has no initializer and is not definitely assigned in the constructor. 7 | 8 | @Inject()

9 | ctx: FaaSContext; | ^ 10 | 11 | @Func('api.render', { middleware: [ 'fmw:staticFile' ]}) 12 | async render() {

ERROR Build failed with errors. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! midway-faas-vue-demo@1.0.0 build: vue-cli-service build npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the midway-faas-vue-demo@1.0.0 build script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:

czy88840616 commented 4 years ago

是因为 vue 默认生成的 tsconfig.json 里默认设置了严格初始化,可以添加 "strictPropertyInitialization": false 处理。

czy88840616 commented 4 years ago

已默认处理。