访问任何页面时,我的项目突然开始出现以下错误:
height
从头开始重建项目后,我发现原因是在dev命令上设置的节点路径,如下所示:
JSON.parse: unexpected character at line 1 column 1 of the JSON data
这是描述here的通用解决方案,用于启用带有typescript enable的nextjs项目的导入时使用绝对路径。
要进行复制,请按照以下步骤操作:
- 运行npm init next-app创建一个应用。根据您的喜好为项目命名。
- 将package.json文件上的dev命令更改为:dev:“ NODE_PATH =。next”
- 运行npm运行开发
- 访问该站点。您应该看到一个空白页,而不是简介页。
- 在浏览器上打开JavaScript控制台。错误应该在那里。
这是我发现的唯一在本地和Vercel云中都可以使用的解决方案。 保持这种绝对路径的任何修复方法都很好
在这里堆栈。并没有增加多少,但是可以通过任何方式添加:
//package.json file
"NODE_PATH=. next"
所有组件都是最新的:
<anonymous> platform.js:14
NextJS 3
js
__webpack_require__
fn
<anonymous> detect-focus.js:19
NextJS 3
js
__webpack_require__
fn
<anonymous> supports.js:21
NextJS 3
js
__webpack_require__
fn
<anonymous> valid-tabindex.js:55
NextJS 3
js
__webpack_require__
fn
<anonymous> tabindex-value.js:22
NextJS 3
js
__webpack_require__
fn
<anonymous> focus-relevant.js:19
NextJS 3
js
__webpack_require__
fn
<anonymous> focusable.js:7
NextJS 3
js
__webpack_require__
fn
<anonymous> focusable.strict.js:8
NextJS 3
js
__webpack_require__
fn
<anonymous> focusable.js:42
NextJS 3
<anonymous> disabled.js:37
NextJS 3
<anonymous> Overlay.js:29
NextJS 3
<anonymous> index.js:3
NextJS 3
<anonymous> Errors.js:81
NextJS 3
<anonymous> ReactDevOverlay.js:44
NextJS 3
<anonymous> client.js:87
NextJS 3
<anonymous> hot-dev-client.js:1
<anonymous> hot-dev-client.js:375
NextJS 3
<anonymous> webpack-hot-middleware-client.js:1
<anonymous> webpack-hot-middleware-client.js:107
NextJS 3
<anonymous> next-dev.js:1
<anonymous> next-dev.js:149
NextJS 5
使用绝对路径的示例:
//package.json
"dependencies": {
"next": "9.4.1","react": "16.13.1","react-dom": "16.13.1"
}
nodejs version: v12.16.3