Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
182 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 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...