midwayjs / hooks

"Zero" Api / Type Safe / Fullstack Kit / Powerful Backend
MIT License
690 stars 63 forks source link

执行 f deploy 报错 #43

Closed duanzheng closed 3 years ago

duanzheng commented 3 years ago

项目是参考教程使用命令 f create --template-package=@midwayjs-examples/midway-hooks-react 创建的。 没有做任何改动,只修改了 f.yml 中的 Provider 配置为:

provider:
  name: tencent # tencent
  runtime: nodejs10
  region: ap-chengdu
  serviceId: service-3f9vxolr

执行 f deploy 时报错:

TypeError: Cannot read property 'kind' of undefined
    at closetAncestorWhileKind (/Users/tony/Documents/myCode/test_midway_2/node_modules/@midwayjs/next-hooks-compiler/src/util.ts:32:47)
    at closetAncestorWhileKind (/Users/tony/Documents/myCode/test_midway_2/node_modules/@midwayjs/next-hooks-compiler/src/util.ts:120:9)
    at Object.isInsideLambdaOrHook (/Users/tony/Documents/myCode/test_midway_2/node_modules/@midwayjs/next-hooks-compiler/src/util.ts:30:26)
    at processImportNames (/Users/tony/Documents/myCode/test_midway_2/node_modules/@midwayjs/next-hooks-compiler/src/plugin/ref-to-bind.ts:129:8)
    at Identifier (/Users/tony/Documents/myCode/test_midway_2/node_modules/@midwayjs/next-hooks-compiler/src/plugin/ref-to-bind.ts:52:16)
    at Object.enter (/Users/tony/.nvm/versions/node/v10.15.3/lib/node_modules/@midwayjs/faas-cli/node_modules/@midwayjs/mwcc/src/tsquery/query.ts:499:20)
    at visit (/Users/tony/.nvm/versions/node/v10.15.3/lib/node_modules/@midwayjs/faas-cli/node_modules/@midwayjs/mwcc/src/tsquery/traverse.ts:35:31)
    at typescript_1.default.visitEachChild.child (/Users/tony/.nvm/versions/node/v10.15.3/lib/node_modules/@midwayjs/faas-cli/node_modules/@midwayjs/mwcc/src/tsquery/traverse.ts:50:14)
    at visitNode (/Users/tony/.nvm/versions/node/v10.15.3/lib/node_modules/@midwayjs/faas-cli/node_modules/typescript/lib/typescript.js:80329:23)
    at Object.visitEachChild (/Users/tony/.nvm/versions/node/v10.15.3/lib/node_modules/@midwayjs/faas-cli/node_modules/typescript/lib/typescript.js:80757:118)
    at visit (/Users/tony/.nvm/versions/node/v10.15.3/lib/node_modules/@midwayjs/faas-cli/node_modules/@midwayjs/mwcc/src/tsquery/traverse.ts:47:19)
    at typescript_1.default.visitEachChild.child (/Users/tony/.nvm/versions/node/v10.15.3/lib/node_modules/@midwayjs/faas-cli/node_modules/@midwayjs/mwcc/src/tsquery/traverse.ts:50:14)
    at visitNodes (/Users/tony/.nvm/versions/node/v10.15.3/lib/node_modules/@midwayjs/faas-cli/node_modules/typescript/lib/typescript.js:80382:48)
    at Object.visitEachChild (/Users/tony/.nvm/versions/node/v10.15.3/lib/node_modules/@midwayjs/faas-cli/node_modules/typescript/lib/typescript.js:80755:57)
    at visit (/Users/tony/.nvm/versions/node/v10.15.3/lib/node_modules/@midwayjs/faas-cli/node_modules/@midwayjs/mwcc/src/tsquery/traverse.ts:47:19)
    at typescript_1.default.visitEachChild.child (/Users/tony/.nvm/versions/node/v10.15.3/lib/node_modules/@midwayjs/faas-cli/node_modules/@midwayjs/mwcc/src/tsquery/traverse.ts:50:14)
Lxxyx commented 3 years ago

本地验证了一下,打包是正常的,可以尝试升级 Node 版本或者重新安装 node_modules @duanzheng

duanzheng commented 3 years ago

本地验证了一下,打包是正常的,可以尝试升级 Node 版本或者重新安装 node_modules @duanzheng

还是会报错,但这次的报错是和 build 相关:

{ Error: Command failed: npm run build
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! midway-hooks-react-demo@1.0.0 build: `react-app-rewired build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the midway-hooks-react-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:
npm ERR!     /Users/tony/.npm/_logs/2021-01-17T02_18_43_292Z-debug.log

    at ChildProcess.exithandler (child_process.js:294:12)
    at ChildProcess.emit (events.js:198:13)
    at maybeClose (internal/child_process.js:982:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5) killed: false, code: 1, signal: null, cmd: 'npm run build' }

于是我单独执行了一下 npm run build,报错如下:

> midway-hooks-react-demo@1.0.0 build /Users/tony/Documents/myCode/test-midway-3
> react-app-rewired build

Creating an optimized production build...
Failed to compile.

./src/apis/lambda/index.ts
Cannot find module: '@midwayjs/hooks/request'. Make sure this package is installed.

You can install this package by running: yarn add @midwayjs/hooks/request.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! midway-hooks-react-demo@1.0.0 build: `react-app-rewired build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the midway-hooks-react-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:
npm ERR!     /Users/tony/.npm/_logs/2021-01-17T02_19_05_194Z-debug.log

复现步骤:

  1. 执行 f create --template-package=@midwayjs-examples/midway-hooks-react 初始化项目;
  2. 将 f.yml 中的 provider 修改为 tencent;
  3. 执行 f deploynpm run build

我发现当 f.yml 中的 provider 配置为 tencent 和 aliyun 的时候会有不同的表现,不知道是否和这个相关。

duanzheng commented 3 years ago

btw,我的 node 版本是 v10.23.1,@midwayjs/faas-cli 的版本是 1.2.38

jlala commented 3 years ago

我今天也有这个错误,上上周是没问题

Lxxyx commented 3 years ago

@duanzheng @jlala 升级 f cli 到最新版试试看, npm i @midwayjs/faas-cli@latest -g