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

别名设置无效 #5

Closed
duriann opened this issue Oct 11, 2019 · 3 comments
Closed

别名设置无效 #5

duriann opened this issue Oct 11, 2019 · 3 comments

Comments

@duriann
Copy link

duriann commented Oct 11, 2019

你好,我按照文中所述分别设置了paths,alias,tsconfig后依然无法使用别名。。
paths.js:
componentPath: resolveApp('src/app/components')
tsconfig.json:
"baseUrl": "src", "paths": { "src/*":["src/*"], "components/*":["src/app/components/*"] },
webpack.config.js
'components': paths.componentPath

报错:
Cannot find module 'components/home/index'. TS2307

@duriann
Copy link
Author

duriann commented Oct 11, 2019

我发现了 那个baseUrl 我设置的时候提示我只能写'src'或者'node_modules' 于是我写了个'src'
你的配置中写的是'.' 我改成'.' 成功了 这是什么原理?

@BUPTlhuanyu
Copy link
Owner

最新版create-react-app是推荐写src的,并且已经不需要在webpack.config.js中配置alias,直接在tsconfig中配置即可,新版的reactc li将tsconfig中的baseurl添加到了resolve.modules中。建议按照新版create-react-app的要求将本项目的baseurl写成src,那么tsconfig以及alias也要相应的改变。

@BUPTlhuanyu
Copy link
Owner

已经完善别名配置笔记,ts项目无需在alias中添加别名配置,在tsconfig中写即可

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