Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] @umijs/max^4.0.71下,mock文件夹无法识别'@'路径,无法识别d.ts文件的namespace #11329

Open
qian357891 opened this issue Jun 28, 2023 · 4 comments

Comments

@qian357891
Copy link

@umijs/max^4.0.71下,mock文件夹无法识别'@'路径,无法识别d.ts文件的namespace

我看到:feat: support use @ in mock files 这个帖子,上面实现了mock.js文件对@符号的识别,但是对于umijs@4来说似乎不起作用?

Mini Showcase Repository(REQUIRED)

Please provide a minimal reproduction then upload to your GitHub. 请提供 最小重现,并上传到你的 GitHub 仓库

这是我的代码仓库:https://github.com/qian357891/umijs-demo

How To Reproduce

Steps to reproduce the behavior: 1. 2.

文件目录:
|--mock
  |--Information.ts
...
|--src
  |--constants
     |--requestUrl.ts
...

step 1

requestUrl.ts

const CHAT_URL_ROOT = '/api/chat';

export const GET_INFORMATION = CHAT_URL_ROOT + '/information';
export const GET_INFORMATION_LIST = CHAT_URL_ROOT + '/information-list';
export const ADD_INFORMATION = CHAT_URL_ROOT + '/add-information';
export const UPDATE_INFORMATION = CHAT_URL_ROOT + '/update-information';
export const DELETE_INFORMATION = CHAT_URL_ROOT + '/delete-information';

// declare

// declare namespace RequestUrl {
//   const GET_INFORMATION = '/information';
//   const GET_INFORMATION_LIST = '/information-list';
//   const ADD_INFORMATION = '/add-information';
//   const UPDATE_INFORMATION = '/update-information';
//   const DELETE_INFORMATION = '/delete-information';
// }

step 2

Information.ts

import mockjs from 'mockjs';
import { GET_INFORMATION } from '../src/constants/requestUrl'; //可以访问
// import {GET_INFORMATION} from "@/constants/requestUrl"; //无法找到模块


export default {
  ['GET ' + GET_INFORMATION]: mockjs.mock({
    'list|100': [
      { 'id|1-100': 50, 'userId|1-100': 50, title: '@city', digest: '' },
    ],
  }),
};

Expected behavior 1. 2.
我希望能够在mock文件夹中的文件中使用@来代替'../src'路径,或者在mock文件夹下的文件中使用其他文件的declare进行全局常量的声明。我以为是以为mock目录与src同级,但我在src父级文件夹下创建文件夹以及文件,可以正常实现上面两个操作。

无法识别@路径

error - Error: Mock file D:\Doit\web\umijs-antd-pro\mock\demo.ts parse failed.
Cannot find module '@/constants/requestUrl'
Require stack:
- D:\Doit\web\umijs-antd-pro\mock\demo.ts
- D:\Doit\web\umijs-antd-pro\node_modules\.pnpm\@umijs+preset-umi@4.0.71_lyjbtud22co2ahpp6zb6tamdfe\node_modules\@umijs\preset-umi\dist\features\mock\getMockData.js
- D:\Doit\web\umijs-antd-pro\node_modules\.pnpm\@umijs+preset-umi@4.0.71_lyjbtud22co2ahpp6zb6tamdfe\node_modules\@umijs\preset-umi\dist\features\mock\mock.js
- D:\Doit\web\umijs-antd-pro\node_modules\.pnpm\@umijs+core@4.0.71\node_modules\@umijs\core\dist\service\plugin.js
- D:\Doit\web\umijs-antd-pro\node_modules\.pnpm\@umijs+core@4.0.71\node_modules\@umijs\core\dist\service\pluginAPI.js
- D:\Doit\web\umijs-antd-pro\node_modules\.pnpm\@umijs+core@4.0.71\node_modules\@umijs\core\dist\index.js
- D:\Doit\web\umijs-antd-pro\node_modules\.pnpm\umi@4.0.71_elcmqxbumjoc3let763237kd3y\node_modules\umi\dist\service\service.js
- D:\Doit\web\umijs-antd-pro\node_modules\.pnpm\umi@4.0.71_elcmqxbumjoc3let763237kd3y\node_modules\umi\dist\cli\forkedDev.js
- D:\Doit\web\umijs-antd-pro\node_modules\.pnpm\umi@4.0.71_elcmqxbumjoc3let763237kd3y\node_modules\umi\bin\forkedDev.js
    at D:\Doit\web\umijs-antd-pro\node_modules\.pnpm\@umijs+preset-umi@4.0.71_lyjbtud22co2ahpp6zb6tamdfe\node_modules\@umijs\preset-umi\dist\features\mock\getMockData.js:64:13
    at Array.reduce (<anonymous>)
    at getMockData (D:\Doit\web\umijs-antd-pro\node_modules\.pnpm\@umijs+preset-umi@4.0.71_lyjbtud22co2ahpp6zb6tamdfe\node_modules\@umijs\preset-umi\dist\features\mock\getMockData.js:57:10)
    at updateMockData (D:\Doit\web\umijs-antd-pro\node_modules\.pnpm\@umijs+preset-umi@4.0.71_lyjbtud22co2ahpp6zb6tamdfe\node_modules\@umijs\preset-umi\dist\features\mock\mock.js:63:61)
    at FSWatcher.onChange (D:\Doit\web\umijs-antd-pro\node_modules\.pnpm\@umijs+preset-umi@4.0.71_lyjbtud22co2ahpp6zb6tamdfe\node_modules\@umijs\preset-umi\dist\features\mock\mock.js:81:9)
    at FSWatcher.emit (events.js:400:28)
    at FSWatcher.emitWithAll (D:\Doit\web\umijs-antd-pro\node_modules\.pnpm\chokidar@3.5.3\node_modules\chokidar\index.js:541:32)
    at FSWatcher._emit (D:\Doit\web\umijs-antd-pro\node_modules\.pnpm\chokidar@3.5.3\node_modules\chokidar\index.js:632:8)
    at listener (D:\Doit\web\umijs-antd-pro\node_modules\.pnpm\chokidar@3.5.3\node_modules\chokidar\lib\nodefs-handler.js:370:20)

无法识别d.ts文件的namespace

error - Error: Mock file D:\Doit\web\umijs-antd-pro\mock\Information.ts parse failed.
RequestUrl is not defined
    at D:\Doit\web\umijs-antd-pro\node_modules\.pnpm\@umijs+preset-umi@4.0.71_lyjbtud22co2ahpp6zb6tamdfe\node_modules\@umijs\preset-umi\dist\features\mock\getMockData.js:64:13
    at Array.reduce (<anonymous>)
    at getMockData (D:\Doit\web\umijs-antd-pro\node_modules\.pnpm\@umijs+preset-umi@4.0.71_lyjbtud22co2ahpp6zb6tamdfe\node_modules\@umijs\preset-umi\dist\features\mock\getMockData.js:57:10)
    at updateMockData (D:\Doit\web\umijs-antd-pro\node_modules\.pnpm\@umijs+preset-umi@4.0.71_lyjbtud22co2ahpp6zb6tamdfe\node_modules\@umijs\preset-umi\dist\features\mock\mock.js:63:61)
    at Hook.fn (D:\Doit\web\umijs-antd-pro\node_modules\.pnpm\@umijs+preset-umi@4.0.71_lyjbtud22co2ahpp6zb6tamdfe\node_modules\@umijs\preset-umi\dist\features\mock\mock.js:88:5)
    at D:\Doit\web\umijs-antd-pro\node_modules\.pnpm\@umijs+core@4.0.71\node_modules\@umijs\core\dist\service\service.js:112:40
    at _next1 (eval at create (D:\Doit\web\umijs-antd-pro\node_modules\.pnpm\@umijs+bundler-utils@4.0.71\node_modules\@umijs\bundler-utils\compiled\tapable\index.js:1:8410), <anonymous>:34:17)
    at eval (eval at create (D:\Doit\web\umijs-antd-pro\node_modules\.pnpm\@umijs+bundler-utils@4.0.71\node_modules\@umijs\bundler-utils\compiled\tapable\index.js:1:8410), <anonymous>:59:1)

Context

  • Umi Version: @umijs/max^4.0.71
  • Node Version: v14.18.1
  • Platform: websorm@23-01
@fz6m
Copy link
Member

fz6m commented Jun 28, 2023

那个是 2019 年不是 umi 4 的 PR ,目前 umi 4 还不支持使用 alias 。

@qian357891
Copy link
Author

那个是 2019 年不是 umi 4 的 PR ,目前 umi 4 还不支持使用 alias 。

好的,谢谢,我声明的namespace似乎mock也无法解析,请问也是不支持吗?

@fz6m
Copy link
Member

fz6m commented Jun 28, 2023

纯 type 的 namespace 可以被转换掉,namespace 的变量不可以,目前 TS 已经不推荐用 namespace 了,尽量减少使用 namespace 吧。

@qian357891
Copy link
Author

纯 type 的 可以被转换掉, 的变量不可以,目前 TS 已经不推荐用 了,尽量减少使用 吧。namespace``namespace``namespace``namespace

好的,谢谢指导,还有就是我想declare一些常量,但mock文件也无法解析。

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

No branches or pull requests

2 participants