问题描述
在构建它时,我的nextjs应用程序中出现以下错误。尽管我仅使用js,但出于构建原因,我的nextjs应用程序配置了typecipt。
Build error occurred:
TypeError: Cannot destructure property 'protocol' of 'window.location' as it is undefined.
at getLocationorigin (/var/www/Tradersnode/html/Tradersnode/client/mpanel/node_modules/next/dist/next-server/lib/utils.js:3:162)
at Object.<anonymous> (/var/www/Tradersnode/html/Tradersnode/client/mpanel/node_modules/next/dist/next-server/lib/router/utils/parse-relative-url.js:1:206)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/var/www/Tradersnode/html/Tradersnode/client/mpanel/node_modules/next/dist/next-server/lib/router/router.js:1:558)
at Module._compile (internal/modules/cjs/loader.js:1156:30) {
type: 'TypeError'
}
error Command Failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
{
"compilerOptions": {
"target": "es5","lib": [
"dom","dom.iterable","esnext"
],"allowJs": true,"skipLibCheck": true,"strict": false,"forceConsistentCasingInFileNames": true,"noEmit": true,"esModuleInterop": true,"module": "esnext","moduleResolution": "node","resolveJsonModule": true,"isolatedModules": true,"jsx": "preserve"
},"include": [
"next-env.d.ts","**/*.ts","**/*.tsx"
],"exclude": [
"node_modules"
]
}
`var protocol = window.location.protocol; // Don't warn in exotic cases like chrome-extension`
我不确定我在做什么错吗?
解决方法
使用 next dev
运行时出现此错误。
原因是我的 exportTrailingSlash: true
中有 next.config.js
。
因此,例如,如果我打开 /about
,它会产生该错误,但如果我打开 /about/
,一切都会正常运行。