midwayjs / hooks Goto Github PK
View Code? Open in Web Editor NEW"Zero" Api / Type Safe / Fullstack Kit / Powerful Backend
License: MIT License
"Zero" Api / Type Safe / Fullstack Kit / Powerful Backend
License: MIT License
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
Renovate tried to run on this repository, but found these problems.
This repository currently has no open or pending branches.
Executing task: yarn run build <
yarn run v1.22.10
$ node_modules/.bin/mw build
Error! You can try adding the -V parameter for more information output.
E:\Dwyanewang\Projects\demo\midway3\hooks-app\midway.config.ts:9
import { defineConfig } from '@midwayjs/hooks';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:1001:16)
at Module._compile (internal/modules/cjs/loader.js:1049:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:14)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:92:18)
at requireMod (E:\Dwyanewang\Projects\demo\midway3\hooks-app\node_modules@midwayjs\hooks\dist\util-0e1ac72a.cjs.dev.js:130:20)
at getConfigFromFile (E:\Dwyanewang\Projects\demo\midway3\hooks-app\node_modules@midwayjs\hooks\dist\util-0e1ac72a.cjs.dev.js:121:3)
at getConfig (E:\Dwyanewang\Projects\demo\midway3\hooks-app\node_modules@midwayjs\hooks\dist\util-0e1ac72a.cjs.dev.js:99:3)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
终端进程“C:\WINDOWS\System32\cmd.exe /d /c yarn run build”已终止,退出代码: 1。
没有实现服务端渲染? 从目前的demo来看,数据是在客户端获取然后渲染dom
我按照官方文档标准化项目中的单文件构建部署方式尝试构建midway hooks一体化项目,报错如下:
ERROR 25248 MidwayDefinitionNotFoundError: MidwayKoaFramework is not valid in current context at MidwayContainer.getAsync (C:\Code\online-learning\node_modules\@midwayjs\core\dist\context\container.js:425:19) at MidwayFrameworkService.init (C:\Code\online-learning\node_modules\@midwayjs\core\dist\service\frameworkService.js:58:73) at ObjectCreator.doInitAsync (C:\Code\online-learning\node_modules\@midwayjs\core\dist\definitions\objectCreator.js:111:30) at ManagedResolverFactory.createAsync (C:\Code\online-learning\node_modules\@midwayjs\core\dist\context\managedResolverFactory.js:242:34) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async initializeGlobalApplicationContext (C:\Code\online-learning\node_modules\@midwayjs\core\dist\setup.js:99:5) at async BootstrapStarter.init (C:\Code\online-learning\node_modules\@midwayjs\bootstrap\dist\bootstrap.js:27:35) at async Function.run (C:\Code\online-learning\node_modules\@midwayjs\bootstrap\dist\bootstrap.js:102:35) { code: 'MIDWAY_10003', cause: undefined, [Symbol(#NotFoundError)]: Symbol(#NotFoundError) }
请问一体化项目的后端是否支持单文件构建部署?
svelte kit 中使用hooks时 vite 编译抛出错误
❯ cnpm run dev
> [email protected] dev /home/sovlookup/桌面/my-app/test/my-app
> svelte-kit dev
SvelteKit v1.0.0-next.109
local: http://localhost:3000
network: not exposed
Use --host to expose server to other devices on this network
下午4:18:56 [vite] Failed to load source map for /node_modules/_@[email protected]@@midwayjs/core/dist/index.js?v=6e81c65f.
下午4:18:56 [vite] Error when evaluating SSR module /node_modules/_@[email protected]@@midwayjs/core/dist/index.js?v=6e81c65f:
ReferenceError: exports is not defined
at /node_modules/_@[email protected]@@midwayjs/core/dist/index.js?v=6e81c65f:12:23
at instantiateModule (/home/sovlookup/桌面/my-app/test/my-app/node_modules/[email protected]@vite/dist/node/chunks/dep-e9a16784.js:68197:166)
exports is not defined
ReferenceError: exports is not defined
at /node_modules/_@[email protected]@@midwayjs/core/dist/index.js?v=6e81c65f:10:23
at instantiateModule (/home/sovlookup/桌面/my-app/test/my-app/node_modules/[email protected]@vite/dist/node/chunks/dep-e9a16784.js:68197:166)
下午4:18:56 [vite] new dependencies found: @midwayjs/hooks, updating...
下午4:18:56 [vite] Error when evaluating SSR module /node_modules/[email protected]@is-path-inside/index.js?v=6e81c65f:
ReferenceError: require is not defined
at /node_modules/[email protected]@is-path-inside/index.js?v=6e81c65f:2:14
at instantiateModule (/home/sovlookup/桌面/my-app/test/my-app/node_modules/[email protected]@vite/dist/node/chunks/dep-e9a16784.js:68197:166)
下午4:18:56 [vite] Error when evaluating SSR module /node_modules/[email protected]@chalk/source/index.js?v=6e81c65f:
ReferenceError: require is not defined
at /node_modules/[email protected]@chalk/source/index.js?v=6e81c65f:2:20
at instantiateModule (/home/sovlookup/桌面/my-app/test/my-app/node_modules/[email protected]@vite/dist/node/chunks/dep-e9a16784.js:68197:166)
下午4:18:56 [vite] Error when evaluating SSR module /node_modules/[email protected]@jiti/lib/index.js?v=6e81c65f:
ReferenceError: module is not defined
at /node_modules/[email protected]@jiti/lib/index.js?v=6e81c65f:12:1
at instantiateModule (/home/sovlookup/桌面/my-app/test/my-app/node_modules/[email protected]@vite/dist/node/chunks/dep-e9a16784.js:68197:166)
下午4:18:56 [vite] Error when evaluating SSR module /node_modules/[email protected]@globby/index.js?v=6e81c65f:
ReferenceError: require is not defined
at /node_modules/[email protected]@globby/index.js?v=6e81c65f:2:12
at instantiateModule (/home/sovlookup/桌面/my-app/test/my-app/node_modules/[email protected]@vite/dist/node/chunks/dep-e9a16784.js:68197:166)
下午4:18:56 [vite] Error when evaluating SSR module /node_modules/[email protected]@consola/dist/consola.js?v=6e81c65f:
ReferenceError: require is not defined
at /node_modules/[email protected]@consola/dist/consola.js?v=6e81c65f:1:90
at instantiateModule (/home/sovlookup/桌面/my-app/test/my-app/node_modules/[email protected]@vite/dist/node/chunks/dep-e9a16784.js:68197:166)
下午4:18:56 [vite] Error when evaluating SSR module /node_modules/[email protected]@pkg-dir/index.js?v=6e81c65f:
ReferenceError: require is not defined
at /node_modules/[email protected]@pkg-dir/index.js?v=6e81c65f:2:14
at instantiateModule (/home/sovlookup/桌面/my-app/test/my-app/node_modules/[email protected]@vite/dist/node/chunks/dep-e9a16784.js:68197:166)
下午4:18:56 [vite] Error when evaluating SSR module /node_modules/[email protected]@koa-static-cache/index.js?v=6e81c65f:
ReferenceError: require is not defined
at /node_modules/[email protected]@koa-static-cache/index.js?v=6e81c65f:1:14
at instantiateModule (/home/sovlookup/桌面/my-app/test/my-app/node_modules/[email protected]@vite/dist/node/chunks/dep-e9a16784.js:68197:166)
下午4:18:56 [vite] Error when evaluating SSR module /node_modules/[email protected]@art-template/index.js?v=6e81c65f:
ReferenceError: require is not defined
at /node_modules/[email protected]@art-template/index.js?v=6e81c65f:1:18
at instantiateModule (/home/sovlookup/桌面/my-app/test/my-app/node_modules/[email protected]@vite/dist/node/chunks/dep-e9a16784.js:68197:166)
下午4:18:56 [vite] Failed to load source map for /node_modules/_@[email protected]@@midwayjs/decorator/dist/index.js?v=6e81c65f.
下午4:18:56 [vite] Error when evaluating SSR module /node_modules/_@[email protected]@@midwayjs/decorator/dist/index.js?v=6e81c65f:
ReferenceError: exports is not defined
at /node_modules/_@[email protected]@@midwayjs/decorator/dist/index.js?v=6e81c65f:12:23
at instantiateModule (/home/sovlookup/桌面/my-app/test/my-app/node_modules/[email protected]@vite/dist/node/chunks/dep-e9a16784.js:68197:166)
下午4:18:56 [vite] Error when evaluating SSR module /node_modules/[email protected]@axios/index.js?v=6e81c65f:
ReferenceError: module is not defined
at /node_modules/[email protected]@axios/index.js?v=6e81c65f:1:1
at instantiateModule (/home/sovlookup/桌面/my-app/test/my-app/node_modules/[email protected]@vite/dist/node/chunks/dep-e9a16784.js:68197:166)
下午4:18:56 [vite] Error when evaluating SSR module /node_modules/[email protected]@upath/build/code/upath.js?v=6e81c65f:
ReferenceError: require is not defined
at /node_modules/[email protected]@upath/build/code/upath.js?v=6e81c65f:23:1
at instantiateModule (/home/sovlookup/桌面/my-app/test/my-app/node_modules/[email protected]@vite/dist/node/chunks/dep-e9a16784.js:68197:166)
下午4:18:57 [vite] Error when evaluating SSR module /node_modules/[email protected]@axios/index.js:
ReferenceError: module is not defined
at /node_modules/[email protected]@axios/index.js:1:1
at instantiateModule (/home/sovlookup/桌面/my-app/test/my-app/node_modules/[email protected]@vite/dist/node/chunks/dep-e9a16784.js:68197:166)
下午4:18:57 [vite] Error when evaluating SSR module /node_modules/[email protected]@lodash.clonedeep/index.js:
ReferenceError: module is not defined
at /node_modules/[email protected]@lodash.clonedeep/index.js:1748:1
at instantiateModule (/home/sovlookup/桌面/my-app/test/my-app/node_modules/[email protected]@vite/dist/node/chunks/dep-e9a16784.js:68197:166)
下午4:18:57 [vite] Error when evaluating SSR module /node_modules/[email protected]@debug/src/index.js:
ReferenceError: module is not defined
at /node_modules/[email protected]@debug/src/index.js:9:2
at instantiateModule (/home/sovlookup/桌面/my-app/test/my-app/node_modules/[email protected]@vite/dist/node/chunks/dep-e9a16784.js:68197:166)
> node_modules/_@[email protected]@@midwayjs/hooks-core/dist/midwayjs-hooks-core.esm.js:8:15: error: No matching export in "browser-external:path" for import "join"
8 │ import path, { join as join$1, resolve } from 'path';
╵ ~~~~
> node_modules/_@[email protected]@@midwayjs/hooks-core/dist/midwayjs-hooks-core.esm.js:8:31: error: No matching export in "browser-external:path" for import "resolve"
8 │ import path, { join as join$1, resolve } from 'path';
╵ ~~~~~~~
> node_modules/_@[email protected]@@midwayjs/hooks-core/dist/midwayjs-hooks-core.esm.js:16:9: error: No matching export in "browser-external:fs" for import "existsSync"
16 │ import { existsSync, readFileSync } from 'fs';
╵ ~~~~~~~~~~
> node_modules/_@[email protected]@@midwayjs/hooks-core/dist/midwayjs-hooks-core.esm.js:16:21: error: No matching export in "browser-external:fs" for import "readFileSync"
16 │ import { existsSync, readFileSync } from 'fs';
╵ ~~~~~~~~~~~~
> node_modules/_@[email protected]@@midwayjs/hooks/dist/midwayjs-hooks.esm.js:2:9: error: No matching export in "node_modules/_@[email protected]@@midwayjs/hooks-core/dist/midwayjs-hooks-core.esm.js" for import "ApiConfig"
2 │ export { ApiConfig, defineConfig, hooks, superjson } from '@midwayjs/hook...
╵ ~~~~~~~~~
下午4:18:57 [vite] error while updating dependencies:
Error: Build failed with 5 errors:
node_modules/_@[email protected]@@midwayjs/hooks-core/dist/midwayjs-hooks-core.esm.js:8:15: error: No matching export in "browser-external:path" for import "join"
node_modules/_@[email protected]@@midwayjs/hooks-core/dist/midwayjs-hooks-core.esm.js:8:31: error: No matching export in "browser-external:path" for import "resolve"
node_modules/_@[email protected]@@midwayjs/hooks-core/dist/midwayjs-hooks-core.esm.js:16:9: error: No matching export in "browser-external:fs" for import "existsSync"
node_modules/_@[email protected]@@midwayjs/hooks-core/dist/midwayjs-hooks-core.esm.js:16:21: error: No matching export in "browser-external:fs" for import "readFileSync"
node_modules/_@[email protected]@@midwayjs/hooks/dist/midwayjs-hooks.esm.js:2:9: error: No matching export in "node_modules/_@[email protected]@@midwayjs/hooks-core/dist/midwayjs-hooks-core.esm.js" for import "ApiConfig"
at failureErrorWithLog (/home/sovlookup/桌面/my-app/test/my-app/node_modules/[email protected]@esbuild/lib/main.js:1443:15)
at /home/sovlookup/桌面/my-app/test/my-app/node_modules/[email protected]@esbuild/lib/main.js:1125:28
at runOnEndCallbacks (/home/sovlookup/桌面/my-app/test/my-app/node_modules/[email protected]@esbuild/lib/main.js:915:63)
at buildResponseToResult (/home/sovlookup/桌面/my-app/test/my-app/node_modules/[email protected]@esbuild/lib/main.js:1123:7)
at /home/sovlookup/桌面/my-app/test/my-app/node_modules/[email protected]@esbuild/lib/main.js:1230:14
at /home/sovlookup/桌面/my-app/test/my-app/node_modules/[email protected]@esbuild/lib/main.js:606:9
at handleIncomingPacket (/home/sovlookup/桌面/my-app/test/my-app/node_modules/[email protected]@esbuild/lib/main.js:703:9)
at Socket.readFromStdout (/home/sovlookup/桌面/my-app/test/my-app/node_modules/[email protected]@esbuild/lib/main.js:573:7)
at Socket.emit (node:events:365:28)
at Socket.emit (node:domain:470:12)
https://github.com/SOVLOOKUP/midway-svelte
https://codesandbox.io/s/keen-curran-pich3
使hooks能与kit一同使用或者给出解决方向
调试框架:svelte-kit
复现仓库:https://github.com/sovlookup/midway-svelte
操作系统:Linux 5.13
❯ cnpm run dev
> [email protected] dev /home/sovlookup/桌面/秦淮/midway-svelte
> svelte-kit dev
SvelteKit v1.0.0-next.115
local: http://localhost:3000
network: not exposed
Use --host to expose server to other devices on this network
上午10:31:26 [vite] Internal server error: request to http://127.0.0.1:7001/api failed, reason: socket hang up
at ClientRequest.<anonymous> (/home/sovlookup/桌面/秦淮/midway-svelte/node_modules/[email protected]@node-fetch/lib/index.js:1461:11)
at ClientRequest.emit (node:events:394:28)
at ClientRequest.emit (node:domain:470:12)
at Socket.socketOnEnd (node:_http_client:471:9)
at Socket.emit (node:events:406:35)
at Socket.emit (node:domain:470:12)
at endReadableNT (node:internal/streams/readable:1329:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
node:events:371
throw er; // Unhandled 'error' event
^
Error [ERR_IPC_CHANNEL_CLOSED]: Channel closed
at new NodeError (node:internal/errors:363:5)
at ChildProcess.target.send (node:internal/child_process:724:16)
at /home/sovlookup/桌面/秦淮/midway-svelte/node_modules/_@[email protected]@@midwayjs/cli-plugin-dev/dist/index.js:325:24
at new Promise (<anonymous>)
at DevPlugin.getData (/home/sovlookup/桌面/秦淮/midway-svelte/node_modules/_@[email protected]@@midwayjs/cli-plugin-dev/dist/index.js:318:16)
at /home/sovlookup/桌面/秦淮/midway-svelte/node_modules/_@[email protected]@@midwayjs/serverless-dev-pack/dist/common.js:64:16
at waitDev (/home/sovlookup/桌面/秦淮/midway-svelte/node_modules/_@[email protected]@@midwayjs/serverless-dev-pack/dist/common.js:39:30)
at Timeout._onTimeout (/home/sovlookup/桌面/秦淮/midway-svelte/node_modules/_@[email protected]@@midwayjs/serverless-dev-pack/dist/common.js:49:13)
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7)
Emitted 'error' event on ChildProcess instance at:
at node:internal/child_process:728:35
at processTicksAndRejections (node:internal/process/task_queues:78:11) {
code: 'ERR_IPC_CHANNEL_CLOSED'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] dev: `svelte-kit dev`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] dev 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! /home/sovlookup/.npm/_logs/2021-06-18T02_31_27_744Z-debug.log
⠙ Midway Starting ✘ [ERROR] [plugin vite:dep-scan] Cannot find module '@enums'
Require stack:
@midwayjs/hooks: 3.0.0-rc.9
demo: https://github.com/94cstyles/midway-hook
经排查可能因
https://github.com/midwayjs/hooks/blob/main/packages/bundler/src/index.ts#L113
在 vite plugin 中 require 了后端服务代码,且没有对应的 alias 支持,导致该异常。
我尝试通过 module-alias
来解决该问题
{
"scripts": {
"dev": "MIDWAY_SERVER_ENV=local node -r module-alias/register ./node_modules/.bin/hooks dev"
},
"_moduleAliases": {
"@enums": "./src/server/enum.ts"
}
}
Cannot find module
问题得到解决,但又引来 typeorm 问题....
[plugin vite:dep-scan] Column type for Member#id is not defined and cannot be guessed. Make sure you have turned on an "emitDecoratorMetadata": true option in tsconfig.json. Also make sure you have imported "reflect-metadata" on top of the main entry file in your application (before any entity imported).If you are using JavaScript instead of TypeScript you must explicitly provide a column type.
求解 ~
在可见的未来,Hooks 将会增加许多配置项来适应不同的场景,而 f.yml
与 Serverless 场景强绑定且表现力不足,因此需要提出在 Hooks 项目下的构建配置方式。
export default {
runtime: 'async_hooks' | 'compiler',
// ...config
}
hooks start 当前端是一个SPA应用时,会出现不能路由。
curl http://127.0.0.1:3000/a
实际效果
什么也不返回
期待效果
返回的 curl http://127.0.0.1:3000 一样的结果
Hello,
In most cases that means something is wrong with your current Yarn setup and we can't fix it automatically:
Yarn Error: Invariant Violation: should have a resolved reference
Yarn Error: Invariant Violation: should have a resolved reference
Yarn Error: Invariant Violation: should have a resolved reference
After you've fixed the problem, please activate this project again in the Depfu Dashboard.
👉 We will not send you further PRs until this is fixed and the repo is activated again.
If you need help or this looks like an error on our side, please send us an email.
开发分支:https://github.com/midwayjs/hooks/tree/main
想要让小程序可以访问 react-faas hook提供的一个http访问的接口,并且返回一个json对象 怎么实现呢?
目前看到是类似 create-react-app 创建的前端模板代码,想用 umi 那套东西,可以集成在一起吗?
背景
需求
------- 第二个问题 -----
在后端 接口A调用接口B 也如何拦截错误?
现在和前端一样表现都会走成功
curl -o- -L https://yarnpkg.com/install.sh | bash
我尝试将例子中的koa修改为eggjs,出现如下错误,是还没有支持吗?
/home/sovlookup/桌面/node/hooks/examples/svelte/src/App.svelte:1
(function (exports, require, module, __filename, __dirname) { <script lang="ts">
^
SyntaxError: Unexpected token '<'
at new Script (node:vm:99:7)
at p._moduleCompile (/home/sovlookup/桌面/node/hooks/examples/svelte/node_modules/[email protected]@jiti/dist/v8cache.js:2:3154)
at Module.o._compile (/home/sovlookup/桌面/node/hooks/examples/svelte/node_modules/[email protected]@jiti/dist/v8cache.js:2:2705)
at Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
at Object.require.extensions.<computed> [as .js] (/home/sovlookup/桌面/node/hooks/examples/svelte/node_modules/[email protected]@ts-node/src/index.ts:1045:43)
at Module.load (node:internal/modules/cjs/loader:989:32)
at Function.Module._load (node:internal/modules/cjs/loader:829:14)
at Module.require (node:internal/modules/cjs/loader:1013:19)
at n (/home/sovlookup/桌面/node/hooks/examples/svelte/node_modules/[email protected]@jiti/dist/v8cache.js:2:2472)
at Object.<anonymous> (/home/sovlookup/桌面/node/hooks/examples/svelte/src/main.ts:1:1)
[ Midway ] start error: Unexpected token '<'
版本: 3.0.0
尝试使用 socketio 组件,同样的代码在传统方案下 ws 可连接,一体化方案则无响应,唯一的差异就是在引入组件的方式
import { createConfiguration, hooks } from '@midwayjs/hooks';
import * as Koa from '@midwayjs/koa';
import * as socketio from '@midwayjs/socketio';
export default createConfiguration({
imports: [Koa, socketio, hooks()],
...
})
import { Configuration, App } from '@midwayjs/decorator';
import * as koa from '@midwayjs/koa';
import * as socketio from '@midwayjs/socketio';
@Configuration({
imports: [
koa,
socketio,
...
})
如题所示,使用pnpm安装依赖后无法正常启动项目,是前后端一体化的模板那个
比如需要在服务端动态生成qrcode的场景下
如下代码:
import { Api, Get, useContext } from "@midwayjs/hooks";
export const test = Api(Get(), async () => {
const ctx = useContext();
ctx.type = "png";
const base64Png =
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFQAAABUCAYAAAAcaxDBAAAAAklEQVR4AewaftIAAAIySURBVO3BQW5rSQwEwSyi73/lnFkSWrTxIFryBxgRQD5I5SYJncpNEjqVLgmfVKxRxRpVrFGHFyqTkjApCZ3KEyqTktAVa1SxRhVr1OEHSXhC5YkkdCqflIQnVG6KNapYo4o1qlijijWqWKOKNerwZSpdEv5lxRpVrFHFGnX4gco3qfwmlUnFGlWsUcUadXiRhE9KQqfSJaFT6ZLQqdwk4TcVa1SxRhVr1FH5JpUuCZNUPqlYo4o1qlijDg8l4UalS8KNyo3KJyXhRuWmWKOKNapYow4vktCpdCpdEm5UbpLQqXRJuFHpktCp3CShU3kiCV2xRhVrVLFGBZA3qHRJuFF5RxLeodIloVPpknCj0hVrVLFGFWtUAGlUbpLwhEqXhN+k0iWhU7lJwo1Kl4SuWKOKNapYo45Kl4RO5UalS0KXhBuVLgmdSpeEmyR8U7FGFWtUsUbF//FFSehUuiRMUrlJQqfyRLFGFWtUsUadJHySyjtUbpLQqXRJuFHpknCj0hVrVLFGFWvU4YXKpCTcqHRJ6FS6JLxDpUtCl4R3FGtUsUYVa9ThB0l4QuWJJHQqXRKeULlJQqfSJaFTuUlCV6xRxRpVrFGHPyYJncpNErok3Kh0SbhJQqfSqXTFGlWsUcUadfgylS4JXRI6lRuVLgldEp5Q6ZJwU6xRxRpVrFGHH6j8JUm4SUKn0iXhRuVGpUtCV6xRxRpVrFGHF0n4y1TeofKOJHQqXbFGFWtUsUb9B7x87rg3rZ9/AAAAAElFTkSuQmCC";
const png = base64Png.replace(/^data:image\/\w+;base64,/, "");
ctx.body = Buffer.from(png, "base64");
});
返回的图会有问题
尝试过在标准项目,相同的代码是图片是正常显示的
我是新手 我用 v3的hooks : ‘npx degit https://github.com/midwayjs/hooks/examples/vue-faas ./hooks-app‘ 起了一个项目, 部署到 aliyunFC, 但是我发现 vue 前端没有发布出去, 我想问下在这种情况下, 前端是怎么部署的?
首先 我调整了
midway.config.ts
因为编译不通过:
const vue = require('@vitejs/plugin-vue');
const { defineConfig } = require('@midwayjs/hooks-kit');
module.exports = defineConfig({
vite: {
plugins: [vue()]
}
});
我发布使用 npm run build && mw deploy
到 阿里云 FC, 我发现 部署过程并没有 将 生成的 dist/_client 打包到 serverless ,
后来又试用了 midway v1 的 mindway-hooks-vue3
模版, 是可以成功的, 我看了下 主要是 @midwayjs/faas-middleware-static-file
这个起的作用, 而这个用在 v3上 我也没搞明白怎么用.
根据介绍,我使用 @midwayjs/static-file
先简单手动吧 dist/_client 拷贝到 build
目录
部署到阿里云FC , 访问结果 404,
没有起作用,
后面我参考 midway v1 的 mindway-hooks-vue3
, 想是不是要一个 指向‘/’ 首页的api啊,
于是建了一个
export const index = Api(Get('/'), async () => {
});
但是 怎么引入static-file 组件 要怎么写没搞明白
目前就卡在这里
本 RFC 旨在提出在 Hooks 项目下的单元测试语法与实现方式。
lambda/demo.ts
export async function get() {
return 'get'
}
export async function post (value: string) {
return value
}
import { get, post } from '../demo'
import { invoke } from '@midwayjs/hooks-testing-library'
test('lambda get', () => {
const { data } = await invoke(() => get())
expect(data).toEqual('get')
})
test('lambda post', () => {
const { data } = await invoke(() => post('from test'))
expect(data).toEuqal('from test')
})
lambda/demo.ts
export async function query() {
const ctx = useContext()
return ctx.query
}
export async function header () {
return ctx.header
}
import { query, header } from '../demo'
import { invoke } from '@midwayjs/hooks-testing-library'
test('lambda with query', () => {
const { data } = await invoke(() => query(), {
query: {
from: 'test'
}
})
expect(data).toEqual({
from: 'test'
})
})
test('lambda with header', () => {
const { data } = await invoke(() => header(), {
header: {
from: 'test'
}
})
expect(data).toEqual({
from: 'test'
})
})
lambda/demo.ts
export async function setStatus() {
const ctx = useContext()
ctx.status = 404
return null
}
export async function setHeader () {
const ctx = useContext()
ctx.set('Access-Control-Allow-Origin', '*')
return null
}
test('lambda with response status', () => {
const { data, status } = await invoke(() => setStatus())
expect(status).toEqual(404)
})
test('lambda with response header', () => {
const { data, header } = await invoke(() => setHeader())
expect(header['Access-Control-Allow-Origin']).toEqual('*')
})
declare function invoke(lambda: Function, context: FaaSContext) :Response
// inspire by axios: https://github.com/axios/axios#response-schema
type Response = {
// `data` is the response that was provided by the server
data: {},
// `status` is the HTTP status code from the server response
status: 200,
// `statusText` is the HTTP status message from the server response
statusText: 'OK',
// `headers` the HTTP headers that the server responded with
// All header names are lower cased and can be accessed using the bracket notation.
// Example: `response.headers['content-type']`
headers: {},
// `config` is the config that was provided to test client
config: {},
}
由于前后端测试环境不同,为避免冲突与不必要的问题,约定如下:
使用 ts-jest 提供的 AST transformers option
将所有导入的 lambda 编译为返回调用信息,并通过 serverless-invoke 做调用。
调试框架:svelte-kit
复现仓库:https://github.com/sovlookup/midway-svelte
操作系统:Linux 5.13
❯ cnpm run build
> [email protected] build /home/sovlookup/桌面/秦淮/midway-svelte
> svelte-kit build
vite v2.3.7 building for production...
✓ 92 modules transformed.
.svelte-kit/output/client/_app/manifest.json 1.56kb
.svelte-kit/output/client/_app/layout.svelte-646c1d37.js 0.49kb / brotli: 0.29kb
.svelte-kit/output/client/_app/pages/index.svelte-a4c45f6d.js 1.16kb / brotli: 0.57kb
.svelte-kit/output/client/_app/error.svelte-71b8bb5c.js 1.19kb / brotli: 0.57kb
.svelte-kit/output/client/_app/assets/start-a8cd1609.css 0.16kb / brotli: 0.10kb
.svelte-kit/output/client/_app/chunks/vendor-f965f831.js 18.55kb / brotli: 6.31kb
.svelte-kit/output/client/_app/start-d1d56062.js 17.18kb / brotli: 5.50kb
.svelte-kit/output/client/_app/chunks/index-650274ee.js 24.97kb / brotli: 7.49kb
vite v2.3.7 building SSR bundle for production...
✓ 10 modules transformed.
.svelte-kit/output/server/manifest.json 0.17kb
.svelte-kit/output/server/app.js 9.49kb
Run npm run preview to preview your production build locally.
> Using @sveltejs/adapter-node
> Directory import '/home/sovlookup/桌面/秦淮/midway-svelte/node_modules/@midwayjs/hooks-core/request' is not supported resolving ES modules imported from /home/sovlookup/桌面/秦淮/midway-svelte/.svelte-kit/output/server/app.js
Did you mean to import @[email protected]@@midwayjs/hooks-core/request/dist/midwayjs-hooks-core-request.cjs.js?
Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/home/sovlookup/桌面/秦淮/midway-svelte/node_modules/@midwayjs/hooks-core/request' is not supported resolving ES modules imported from /home/sovlookup/桌面/秦淮/midway-svelte/.svelte-kit/output/server/app.js
Did you mean to import @[email protected]@@midwayjs/hooks-core/request/dist/midwayjs-hooks-core-request.cjs.js?
at new NodeError (node:internal/errors:363:5)
at finalizeResolution (node:internal/modules/esm/resolve:303:17)
at moduleResolve (node:internal/modules/esm/resolve:742:10)
at Loader.defaultResolve [as _resolve] (node:internal/modules/esm/resolve:853:11)
at Loader.resolve (node:internal/modules/esm/loader:89:40)
at Loader.getModuleJob (node:internal/modules/esm/loader:242:28)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:73:40)
at link (node:internal/modules/esm/module_job:72:36)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `svelte-kit build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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! /home/sovlookup/.npm/_logs/2021-06-18T02_43_51_382Z-debug.log
包版本:3.0.0
NodeJS:16.9.1(可能和版本没关系)
今天使用 hooks build
部署项目的时候一切正常,但执行 hooks start
时发现:
2022-05-22 18:11:22,916 ERROR 1016 MidwayDuplicateRouteError: Duplicate router "get /api/acgm" at "apiAcgmIndex.handler" and "apiAcgm.handler"
at WebRouterCollector.checkDuplicateAndPush (/Users/paul/Documents/项目/Midway-Startup/Paul-API-Next/node_modules/@midwayjs/core/dist/common/webRouterCollector.js:322:19)
at WebRouterCollector.collectRoute (/Users/paul/Documents/项目/Midway-Startup/Paul-API-Next/node_modules/@midwayjs/core/dist/common/webRouterCollector.js:135:22)
at WebRouterCollector.analyze (/Users/paul/Documents/项目/Midway-Startup/Paul-API-Next/node_modules/@midwayjs/core/dist/common/webRouterCollector.js:29:18)
at WebRouterCollector.getRouterTable (/Users/paul/Documents/项目/Midway-Startup/Paul-API-Next/node_modules/@midwayjs/core/dist/common/webRouterCollector.js:297:24)
at KoaControllerGenerator.loadMidwayController (/Users/paul/Documents/项目/Midway-Startup/Paul-API-Next/node_modules/@midwayjs/core/dist/common/webGenerator.js:64:45)
at MidwayKoaFramework.loadMidwayController (/Users/paul/Documents/项目/Midway-Startup/Paul-API-Next/node_modules/@midwayjs/koa/dist/framework.js:80:30)
at MidwayKoaFramework.run (/Users/paul/Documents/项目/Midway-Startup/Paul-API-Next/node_modules/@midwayjs/koa/dist/framework.js:104:20)
at MidwayFrameworkService.runFramework (/Users/paul/Documents/项目/Midway-Startup/Paul-API-Next/node_modules/@midwayjs/core/dist/service/frameworkService.js:113:41)
at MidwayLifeCycleService.init (/Users/paul/Documents/项目/Midway-Startup/Paul-API-Next/node_modules/@midwayjs/core/dist/service/lifeCycleService.js:58:37)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
code: 'MIDWAY_10008',
cause: undefined
}
提示路由冲突,但我没发现出具体冲突的原因,我搜到了这篇 PR,找到了错误提示的出处:midwayjs/midway#1023 之后评论说明了下情况...
项目目录结构:
api
- admin
-- acgm
--- add.ts
- acgm.ts
理论上的路由地址:
POST /api/admin/acgm/add
GET /api/acgm
试了下改 admin/acgm
的路由名称重新部署无效,发现是项目迭代原因所致,/api/acgm
曾经是个目录,但后期变回了文件,旧的文件不会随着部署自动清理,删除掉 dist
重新生成就可以了。
看看官方怎么认为这件事吧,我认为应该在部署的时候自动删除下旧的部署内容,而不是一昧直接覆盖上去==
使用上述代码仓库,运行npm run build 即可复现。
项目是参考教程使用命令 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)
可以提供其他下载方式吗?
3.0.0 使用 react 模板,运行 pnpm dev
,出现错误
Error: Please add @midwayjs/mock to your devDependencies
以hooks - example / vue为例,在开发环境中可以正常安装所有依赖,但在生产环境中始终会缺少几个包,如:vue-plugin等.
在服务器部署的时候,只能用开发环境构建,因为生产环境缺包无法正常使用.开发环境构建好的包只能通过npm start运行,通过Bootstrap启动时又会提示新的错误.
版本
node v17.3.1
"@midwayjs/core": "3.0.13",
"@midwayjs/decorator": "^3.0.10",
"@midwayjs/hooks": "^3.0.0-rc.8",
"@midwayjs/hooks-kit": "^3.0.0-rc.10",
"@midwayjs/koa": "^3.0.13",
"@midwayjs/rpc": "^3.0.0-rc.10"
重现链接
https://github.com/chriswjou/hooks-validate-issue
重现步骤
npm run dev 启动项目, vue 项目首页显示message
期望的结果
前端message获得后端Validate组件传递的error message,应为"not email"
实际的结果
message的值为undefined
import db from './database';
...
export const createArticle = Api(
Post(),
Validate(ArticleSchema),
async (article: z.infer<typeof ArticleSchema>) => {
const newArticle = await database.articles.create(article);
return {
id: newArticle.id,
};
}
);
Above is "import db" and below is "database.articles.create".
发布时报错如下:
ReferenceError: describe is not defined
at Object. (C:\Users\kane\Desktop\Dev\clouddev\vite-vue-koa\src\apis\lambda\index.test.ts:5:1)
at Module.o._compile (C:\Users\kane\Desktop\Dev\clouddev\vite-vue-koa\node_modules\jiti\dist\v8cache.js:2:2655)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at MidwayContainer.loadDirectory (C:\Users\kane\Desktop\Dev\clouddev\vite-vue-koa\node_modules@midwayjs\core\dist\context\midwayContainer.js:169:37)
at MidwayContainer.load (C:\Users\kane\Desktop\Dev\clouddev\vite-vue-koa\node_modules@midwayjs\core\dist\context\midwayContainer.js:97:18)
at EmptyFramework.containerDirectoryLoad (C:\Users\kane\Desktop\Dev\clouddev\vite-vue-koa\node_modules@midwayjs\core\dist\baseFramework.js:128:33)
at EmptyFramework.initialize (C:\Users\kane\Desktop\Dev\clouddev\vite-vue-koa\node_modules@midwayjs\core\dist\baseFramework.js:56:20)
at WebRouterCollector.analyze (C:\Users\kane\Desktop\Dev\clouddev\vite-vue-koa\node_modules@midwayjs\core\dist\util\webRouterCollector.js:17:13)
at WebRouterCollector.getFlattenRouterTable (C:\Users\kane\Desktop\Dev\clouddev\vite-vue-koa\node_modules@midwayjs\core\dist\util\webRouterCollector.js:176:13)
at Object.analysisDecorator (C:\Users\kane\Desktop\Dev\clouddev\vite-vue-koa\node_modules@midwayjs\fcli-plugin-package\src\utils.ts:119:18)
at PackagePlugin.analysisCode (C:\Users\kane\Desktop\Dev\clouddev\vite-vue-koa\node_modules@midwayjs\fcli-plugin-package\src\index.ts:533:28)
at CommandCore.execLiftcycle (C:\Users\kane\AppData\Roaming\npm\node_modules@midwayjs\cli\node_modules@midwayjs\command-core\src\core.ts:195:11)
我写了一个导出excel的功能,导出csv可以正常打开,xlsx的话就会报格式错误无法打开,用stream或者buffer都一样。试了一下好像纯文本格式的都正常,其他二进制的格式可能都有问题,请问需要做什么处理吗?
export const test = Api(
Get(`/test`),
Query<any>(),
async () => {
const ctx = useContext<Context>()
const file = fs.createReadStream('./test.zip', 'utf8')
ctx.type = 'zip'
ctx.set('Content-disposition', `attachment; filename=test.zip`)
ctx.statusCode = 200
ctx.body = file
}
)
export const getB = Api(Get(),
Get('/img'),
ContentType('image/png'),
async (repo: string) => {
return fs.createReadStream('src/libs/magick/red-ball.png');
});
connection: keep-alive
content-type: image/png
date: Sat, 07 May 2022 10:22:57 GMT
keep-alive: timeout=5
transfer-encoding: chunked
export const getB3 = Api(Get(),
Get('/img'),
ContentType('html'),
async (repo: string) => {
return fs.createReadStream('index.html');
});
返回html就没有问题
重新clone项目运行example
npm run dev 前端请求后端接口失败
打开开发者工具看到前端在3000端口,后端在7001端口
// 创建 api 模版
npx degit https://github.com/midwayjs/hooks/examples/api ./hooks-app
// 初始化
npm i
// 本地运行
npm run dev
// 报错
[email protected] dev E:\Dwyanewang\Projects\demo\midway3\hooks-app
mw dev --fast
node --trace-warnings ...
to show where the warning was created)[ Midway ] (node:3364) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:3364) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
// 安装 @midwayjs/mock 依赖
E:\Dwyanewang\Projects\demo\midway3\hooks-app>npm i -D @midwayjs/mock
npm WARN deprecated [email protected]: core-js@<3.4 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
npm WARN deprecated [email protected]: Please upgrade to v7.0.2+ of superagent. We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing. See the releases tab for more information at https://github.com/visionmedia/superagent/releases. Thanks to @shadowgate15, @spence-s, and @niftylettuce. Superagent is sponsored by Forward Email at https://forwardemail.net.
npm WARN deprecated [email protected]: Please upgrade to latest, formidable@v2 or formidable@v3! Check these notes: https://bit.ly/2ZEqIau
[email protected] postinstall E:\Dwyanewang\Projects\demo\midway3\hooks-app\node_modules\core-js
node -e "try{require('./postinstall')}catch(e){}"
Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!
The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
https://opencollective.com/core-js
https://www.patreon.com/zloirock
Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
50 packages are looking for funding
run npm fund
for details
// 再次运行
npm run dev
// 报错
E:\Dwyanewang\Projects\demo\midway3\hooks-app>npm run dev
[email protected] dev E:\Dwyanewang\Projects\demo\midway3\hooks-app
mw dev --fast
\ Midway Starting
[ Midway ] start error: (0 , core_1.clearContainerCache) is not a function
TypeError: (0 , core_1.clearContainerCache) is not a function
at create (E:\Dwyanewang\Projects\demo\midway3\hooks-app\node_modules@midwayjs\mock\dist\utils.js:74:36)
at createApp (E:\Dwyanewang\Projects\demo\midway3\hooks-app\node_modules@midwayjs\mock\dist\utils.js:168:29)
at E:\Dwyanewang\Projects\demo\midway3\hooks-app\node_modules@midwayjs\cli-plugin-dev\src\child.ts:47:19
at Object. (E:\Dwyanewang\Projects\demo\midway3\hooks-app\node_modules@midwayjs\cli-plugin-dev\src\child.ts:81:3)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at internal/main/run_main_module.js:17:47
有部分接口通过 hooks 的能力生成接口代码,
有部分想自定义编写接口代码,应该如何编写?
@midwayjs/hooks: 3.0.0-rc.11
问题原因: https://github.com/midwayjs/hooks/blob/main/packages/esrun/src/index.ts#L13
tsconfig paths 的数据类型为 { [key: string]: string[] }
@midwayjs/hooks: 3.0.0-rc.8
midway.config.ts
import path from 'path';
import { defineConfig } from '@midwayjs/hooks-kit';
import react from '@vitejs/plugin-react';
import pages from 'vite-plugin-pages';
export default defineConfig({
source: './src/server',
routes: [
{
baseDir: 'controller',
basePath: '/api'
}
],
vite: {
plugins: [react(), pages({ dirs: 'src/client/pages', extensions: ['tsx'], exclude: ['**/components/**', '**/component/**'] })],
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true
}
}
}
}
});
按照文档
https://www.midwayjs.org/docs/extensions/sequelize
写的是支持一体化项目的
但是实际情况
貌似不能直接import model
import { Photo } from '../entity/Photo';
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.