我正在开发一个项目(Next.js版本8.1.0),并且想升级到9.2版。我将Next.js版本更改为9.2,并且遇到了这个问题:
TypeError:如果没有“ new”,则无法调用类构造函数App 在新的MyApp(/home/node/app/src/.next/server/static/development/pages/_app.js:4384:191) 在processChild上(/home/node/app/node_modules/react-dom/cjs/react-dom-server.node.development.js:2995:14) 在解决时(/home/node/app/node_modules/react-dom/cjs/react-dom-server.node.development.js:2960:5) 在ReactDOMServerRenderer.render(/home/node/app/node_modules/react-dom/cjs/react-dom-server.node.development.js:3435:22) 在ReactDOMServerRenderer.read(/home/node/app/node_modules/react-dom/cjs/react-dom-server.node.development.js:3373:29) 在renderToString(/home/node/app/node_modules/react-dom/cjs/react-dom-server.node.development.js:3988:27) 在渲染时(/home/node/app/node_modules/next/dist/next-server/server/render.js:81:16) 在renderPage(/home/node/app/node_modules/next/dist/next-server/server/render.js:346:16) 在Object.ctx.renderPage(/home/node/app/src/.next/server/static/development/pages/_document.js:2266:26) 在Function.getInitialProps(/home/node/app/src/.next/server/static/development/pages/_document.js:1515:19) 在_callee $(/home/node/app/src/.next/server/static/develop/pages/_document.js:2282:77) 在tryCatch(/home/node/app/src/.next/server/static/development/pages/_document.js:428:40) 在Generator.invoke [作为_invoke](/home/node/app/src/.next/server/static/development/pages/_document.js:654:22) 在Generator.prototype。(匿名函数)[下一个](/home/node/app/src/.next/server/static/development/pages/_document.js:480:21) 在asyncGeneratorStep(/home/node/app/src/.next/server/static/develop/pages/_document.js:124:24) 在_next(/home/node/app/src/.next/server/static/development/pages/_document.js:146:9)
这是我的next.config.js:
const withSass = require('@zeit/next-sass');
const { resolve } = require('path');
let baseUrl = process.env.BASE_URL;
baseUrl = baseUrl && baseUrl.length && '/' !== baseUrl ? baseUrl : '';
module.exports = withSass({
transpileModules: ['file-type'],
webpack(config, options) {
config.module.rules.push({
test: /\.tsx?$/,
use: [
{
loader: 'babel-loader',
options: {
configFile: resolve('babel.config.js'),
},
},
{
loader: 'ts-loader',
options: {
// disable type checker - we will use it in fork plugin
transpileOnly: true,
},
},
],
});
config.module.rules.push({
test: /node_modules\/file-type/,
use: [
{
loader: 'babel-loader',
options: {
configFile: resolve('babel.config.js'),
exclude: /node_modules\/(?!(file-type))/,
include: /node_modules\/file-type/,
sourceType: 'unambiguous',
},
},
],
});
config.resolve.extensions.push('.ts');
config.resolve.extensions.push('.tsx');
config.resolve.extensions.push('.jsx');
/* if (options.isServer) {
config.plugins.push(new ForkTsCheckerWebpackPlugin({ tsconfig: resolve('./tsconfig.json') }));
} */
return config;
},
pageExtensions: ['jsx', 'tsx'],
cssModules: true,
cssLoaderOptions: {
importLoaders: 1,
localIdentName: '[local]___[hash:base64:5]',
},
sassLoaderOptions: {
includePaths: [resolve('src/scss')],
},
webpackDevMiddleware: config => {
if (process.env.ENABLE_WATCH_POLL) {
const watchOptions = {
poll: true,
aggregateTimeout: 500,
ignored: [
'.git/**',
'src/.next/**',
'**/__tests__/**',
'.scannerwork/**',
'cypress/**',
'doc/**',
'node_modules/**',
'src/static/**',
],
};
return { ...config, watch: true, watchOptions };
}
return config;
},
publicRuntimeConfig: {
env: process.env.APP_ENV,
nodeEnv: process.env.NODE_ENV,
apiProxy: process.env.API_PROXY,
subscriptionKey: process.env.OCP_APIM_SUBSCRIPTION_KEY,
apiEndpoint: process.env.API_ENDPOINT,
serverPort: process.env.SERVER_PORT,
gmapApiendpoint: process.env.GMAP_API_KEY,
gigyaApiKey: process.env.GIGYA_API_KEY,
gigyaDatacenter: process.env.GIGYA_DATACENTER,
templateReimbursementLink: process.env.TEMPLATE_REIMBURSEMENT_LINK,
reimbursementStatusLink: process.env.REIMBURSEMENT_STATUS_LINK,
gtmId: process.env.GTM_ID,
captchaSiteKey: process.env.CAPTCHA_SITE_KEY,
baseUrl,
redisPort: process.env.REDIS_PORT,
redisHost: process.env.REDIS_HOST,
redisPassword: process.env.REDIS_PASSWORD,
},
});
答案 0 :(得分:0)
从comment in the GitHub issue you also have commented on中说,要从babel-loader
中删除next.config.js
,因为Next.js已经包含了它。