【发布时间】:2021-06-11 17:32:02
【问题描述】:
我正在将 previus React.js 网站转换为 Next.js 网站,并按照将 create react-app 转换为 next-app 的指南进行操作。
为了使用尾风类,导入图像以在 html vanilla <img> 标记内使用。按照一些关于此事的教程,他们建议安装next-images并使用以下代码配置next.config.js
// next.config.js
const withImages = require('next-images')
module.exports = withImages({
esModule: true
})
这是运行时抛出的错误
./components/partials/Features.js:3:0
Module not found: Can't resolve '/images/features-bg.png'
1 | import React, { useState, useRef, useEffect } from 'react';
2 | import Transition from '../utils/Transition.js';
> 3 | import FeaturesBg from '/images/features-bg.png';
4 | import FeaturesElement from '/images/features-element.png'
5 | import Image from 'next/image';
6 |
我使用的文件夹结构遵循 create next-app 示例,public 文件夹包含所有静态文件。我在其中创建了一个images 文件夹,并验证文件名中没有拼写错误。完整的存储库可用here
有谁知道我做错了什么?
【问题讨论】: