[英]rename export default in index.js
I have component called TModal
that looks like this我有一个名为
TModal
的组件,看起来像这样
const TModal = () => {}
export default TModal
It lives inside src/components/Modal/Modal.js
它位于
src/components/Modal/Modal.js
next to it, there is an index.js
在它旁边,有一个
index.js
this is what index.js does:这就是 index.js 的作用:
export { TModal as Modal } from './Modal'
Then somewhere in my project, I want to import Modal like this然后在我项目的某个地方,我想像这样导入 Modal
import { Modal } from 'components/Modal'
but I keep getting但我不断得到
Attempted import error: 'Modal' is not exported from 'components/Modal'
What's the problem?有什么问题?
jsconfig.json jsconfig.json
{
"compilerOptions": {
"baseUrl": "src",
"target": "es6",
"module": "commonjs",
"jsx": "preserve",
"paths": {
"*": ["./*"]
}
},
"include": ["src"]
}
strcuture结构
src
- components
-- Modal
--- index.js
--- Modal.js
- layouts
-- Auth
--- Auth.js
So as an example, I would want to use Modal
inside Auth.js
例如,我想在
Auth.js
中使用Modal
Since your Modal.js export default, your index.js
should be written as below由于您的 Modal.js 导出默认值,因此您的
index.js
应编写如下
import Modal from './Modal';
export { Modal };
It looks like you are not selecting the file (Modal.js) you are just pointing at the Modal directory.看起来您没有选择您只是指向 Modal 目录的文件 (Modal.js)。 This should fix it if that is the problem.
如果这是问题,这应该解决它。
import { Modal } from 'components/Modal/Modal'
The problem is with TModal
.问题在于
TModal
。 When you export TModal
from js file remove export
keyword.当您从 js 文件中导出
TModal
时,请删除export
关键字。 everything would be working fine.一切都会好起来的。 Help it helps.
帮助它有帮助。
const TModal = () => {}
export TModal
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.