【发布时间】:2020-07-29 02:35:42
【问题描述】:
所以我的server.js 文件中有这个日志:
console.info("LOOGGGGGSSSS")
console.warn("LOOGGGGGSSSS")
console.log("LOOGGGGGSSSS")
console.error("LOOGGGGGSSSS")
我的package.json 有脚本:
"scripts": {
"dev": "next",
"start": "next start"
}
当我使用 npm run start 运行服务器时,一切正常,我可以看到日志,但 npm run dev 没有 console.log() 或 console.error() 工作。
我尝试了选项 quiet true 和 false 但仍然无法正常工作:
const nextJsApp = next({dev, quiet: false}); // no logs in terminal
和
const nextJsApp = next({dev, quiet: true}); // still no logs in terminal
我的next.config.js
require("dotenv").config();
const withCSS = require('@zeit/next-css');
const webpack = require('webpack');
const apiKey = JSON.stringify(process.env.SHOPIFY_API_KEY);
module.exports = withCSS({
webpack: (config) => {
const env = { SHOPIFY_API_KEY: apiKey };
config.plugins.push(new webpack.DefinePlugin(env));
return config;
},
});
【问题讨论】:
-
next命令不会运行您的server.js文件。如果你想运行server.js,运行node server.js。更多信息在这里:nextjs.org/docs/advanced-features/custom-server