Skip to content

[Feature]: 修改mock目录位置 #8693

Description

@tky753

这个功能解决了什么问题?

monorepo项目,希望把mock数据集中到一个目录下。
文档里我没找到相应设置,于是翻看源码,发现可以通过

import { AGGRED_DIR } from '@modern-js/server-core'
AGGRED_DIR.mock = xxx //修改mock目录

希望可以在文档里写明这个配置方法,或者再封装一下让其更易用

但当我把modern.js升级到3.2.0,nodejs 更新到26.1.0后,出现了报错

$ modern dev
  Modern.js Framework v3.2.0

(node:34616) [DEP0205] DeprecationWarning: `module.register()` is deprecated. Use `module.registerHooks()` instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
start   build started...
error   Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'
    at throwIfUnsupportedURLScheme (node:internal/modules/esm/load:199:11)
    at defaultLoad (node:internal/modules/esm/load:82:3)
    at nextLoad (node:internal/modules/esm/hooks:769:28)
    at AsyncLoaderHooksOnLoaderHookWorker.load (node:internal/modules/esm/hooks:406:26)
    at MessagePort.handleMessage (node:internal/modules/esm/worker:251:24)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:843:20)
    at MessagePort.<anonymous> (node:internal/per_context/messageport:23:28)

调试源码,发现是modern.js\packages\server\server\src\helpers\mock.ts 这一句报错

  const { default: mockHandlers, config } = (await import(
    mockFilePath
  )) as MockModule;

暂时没找到解决方案

你期望的 API 是什么样子的?

defineConfig({
  server: {
     path: {
       mock: xxx
     }
  }
})

Metadata

Metadata

Assignees

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions