简体   繁体   English

为什么我无法导入以下文件

[英]Why am I not able to import the following File

This is my src directory -这是我的 src 目录 -

在此处输入图像描述

And while importing the last file (StateProvider.js) in Product.js, this is the error I get while importing StateProvider -在 Product.js 中导入最后一个文件 (StateProvider.js) 时,这是我在导入 StateProvider 时遇到的错误 -

在此处输入图像描述

My import statement from Product.js-我来自 Product.js 的导入声明-

在此处输入图像描述

Can anyone guide me, why my import is not working?谁能指导我,为什么我的导入不起作用?

The error occurs because StateProvider.js is not in the same directory as Product.js .发生错误是因为StateProvider.jsProduct.js不在同一目录中。 You have to specify the import statement like this:您必须像这样指定导入语句:

import StateProvider from '../../StateProvider';

Probably 2 errors.可能有2个错误。

First, If you export the default file you're good to go.首先,如果您导出默认文件,则可以使用 go。

export default StateProvider

Second is if you are on the correct directory.其次是如果您在正确的目录中。

it shouild be应该是

import StateProvider from '../../StateProvider'
import StateProvider from '../../StateProvider'

I also recommend using "Auto Import" extension if you working with Visual Studio Code.如果您使用 Visual Studio Code,我还建议您使用“自动导入”扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM