为什么next.js不能导入组件。有效组件/我现在不知道如何修复此错误
import React from "react";
import Title from '../../../common/components/Title'
export default function Fill(props: any) {
return (
<React.Fragment>
<Title></Title>
</React.Fragment>
)
}Title.js
export default function Title(props) {
return <h1>{ props?.title }</h1>
}导入组件时出错
error - ../../common/components/Title.js
Module parse failed: Unexpected token (2:9)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| export default function Title(props) {
> return <h1>{ props?.title }</h1>
| }
|发布于 2021-05-25 18:46:31
解析父文件夹中的路径
next.config.js
const path = require('path');
module.exports = {
webpack: function (config, { defaultLoaders }) {
const resolvedBaseUrl = path.resolve(config.context, "../../");
config.module.rules = [
...config.module.rules,
{
test: /\.(tsx|ts|js|mjs|jsx)$/,
include: [resolvedBaseUrl],
use: defaultLoaders.babel,
exclude: (excludePath) => {
return /node_modules/.test(excludePath);
},
},
];
return config;
}
};https://stackoverflow.com/questions/67693190
复制相似问题