我正在尝试测试/更改项目从 Vite+React 到 Nextjs+React。
我在这里检查了此页面:https://nextjs.org/learn-pages-router/foundations/from-react-to-nextjs/getting-started-with-nextjs然后我相应地更改了项目。
但是,在运行下一个开发后,我在这里收到以下错误:
const customErrorMap: z.ZodErrorMap = (issue, ctx) => {
Module parse failed: Unexpected token (5:20)
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
webpack.config.js:
我目前没有 webpack.config 文件设置,但我之前尝试过设置它,然后在认为它可能与问题无关后将其删除,因为文档说你不需要它来使用 typescript 和 nextjs。
依赖版本:
{
"typescript": "^5.1.6",
"next": "^14.0.3",
// "vite": "^3.2.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
我发现只有从使用
yarn workspaces
添加的本地工作区导入时才会发生这种情况。
project-name
| - backend
| - frontend
前端/package.json
dependencies: {
"@project-name/backend": "1.0.0",
...
}
yarn 工作空间是否存在兼容性问题?
我需要设置什么才能使其正常工作?
我通过将
transpilePackages
添加到 next.config.js
解决了该问题
/** @type {import('next').NextConfig} */
const nextConfig = {
transpilePackages: ['@project-name/backend'],
}
module.exports = nextConfig