Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
176 views
in Technique[技术] by (71.8m points)

reactjs - How to import a folder and use the folder as path

I am trying to import a folder into a component function, however, it keeps returning the module not found, it works only when I import the whole file location.

For example, I am trying to import a folder called product_images, however, it keeps returning

Module not found: Can't resolve '../../components/context/mockdata/product_images' in 'C:UsersAdminDesktopestsrcpagesProductPage'

How I import is by as per this link

import veg1 from "../../components/context/mockdata/product_images";

I've also tried by declaring it as const as per this link

const product_img_path = require("../../components/context/mockdata/product_images");

Both are returning the same error message.

When I do it as the importing the image instead of a folder, it works

import veg1 from "../../components/context/mockdata/product_images/img_1.jpg";

I tried this link from stackoverflow, however, it also does not let me do import veg1 = 'path'. Concatenate local path + dynamic images from Map - React.Js

question from:https://stackoverflow.com/questions/65840651/how-to-import-a-folder-and-use-the-folder-as-path

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...