Closed yufengwang closed 5 years ago
compiled code in dev mode
Having the same issue when trying to build
It's my wrong next.config.js
@YUFENGWANG Could you tell what was causing the issue in next.config.js?
can this be open? I having the same issue.
"I have the same issue" won't solve the issue. There is no reproduction provided in the initial issue. So please create a new issue that follows the issue template 🙏
In general always provide a reproduction when commenting you have an issue otherwise it's impossible for maintainers to look into it.
It's because of my wrong webpack external config, hope it'll help @jacintorodrigues @AlanPieczonka
function externalsConfig(dir, isServer) {
const externals = [
{
log4js: 'log4js',
'@tuya-fe/next-log4js' : 'commonjs2 @tuya-fe/next-log4js'
},
]
if (!isServer) {
return externals
}
externals.push((context, request, callback) => {
resolve(request, { basedir: dir, preserveSymlinks: true }, (err, res) => {
if (err) {
return callback()
}
// Default pages have to be transpiled
if (res.match(/node_modules[/\\]next[/\\]dist[/\\]pages/)) {
return callback()
}
// Webpack itself has to be compiled because it doesn't always use module relative paths
if (res.match(/node_modules[/\\]webpack/)) {
return callback()
}
if (
res.match(/node_modules[/\\].*\.js$/) &&
!res.match(/node_modules[/\\]@tuya-fe/) &&
!res.match(/node_modules[/\\]lodash-es/)
) {
return callback(null, `commonjs ${request}`)
}
callback()
})
})
return externals
}
I also encouter this after upgrading to version 9
@webdevsyd Check your custom next.config.js
or .babelrc
@YUFENGWANG this is my next.config.js
const resolve = require('resolve')
const withCSS = require('@zeit/next-css')
module.exports = withCSS({
publicRuntimeConfig: {
PORT: process.env.PORT,
NODE_ENV: process.env.NODE_ENV,
EXPRESS_API_URL: process.env.EXPRESS_API_URL,
PLATFORM_URL: process.env.PLATFORM_URL,
APP_URL: process.env.APP_URL,
CUSTOMER_PRIVATE_URL: process.env.CUSTOMER_PRIVATE_URL,
TRACKING_URL: process.env.TRACKING_URL,
RAVEN_DSN: process.env.RAVEN_DSN,
UWAI_COM_URL: process.env.UWAI_COM_URL,
WECHAT_APP_ID: process.env.WECHAT_APP_ID,
WECHAT_APP_SECRET: process.env.WECHAT_APP_SECRET,
GTM_CONTAINER_ID: process.env.GTM_CONTAINER_ID
},
webpack (config, options) {
const { dir, isServer } = options
config.externals = []
if (isServer) {
config.externals.push((context, request, callback) => {
resolve(request, { basedir: dir, preserveSymlinks: true }, (err, res) => {
if (err) {
return callback()
}
if (res.match(/node_modules[/\\]next/)) {
return callback(null, `commonjs ${request}`)
}
callback()
})
})
}
return config
}
})
and this is my babelrc
{
"presets": [
"next/babel"
],
"plugins": [
["import", {"libraryName": "antd", "style": false}],
["styled-components", { "ssr": true, "displayName": true, "preprocess": true }]
]
}
@webdevsyd Check this https://github.com/zeit/next.js/blob/aac5121466f3d58e2c18c4921a9ce36fb7512d2e/packages/next/build/webpack-config.ts#L183 I think it's your wrong external config
The whole webpack (config, options) {
section of your next.config.js looks wrong, I'm not sure how you ended up adding that, would be curious to know.
This is probably related to: https://github.com/zeit/next.js/issues/8175
I have the same issue. With next version 9.0.2 run correctly, but if upgrade it I can see this error.
my next.config.js file
const withLess = require('@zeit/next-less');
let AVAILABLE_LANGUAGES = require('./src/shared/constants/Language');
const BabelPluginTransformImports = require('babel-plugin-transform-imports');
module.exports = withLess({
cssModules : false,
cssLoaderOptions : {
minimize: true,
},
assetPrefix : process.env.ASSET_PREFIX ? process.env.ASSET_PREFIX : '',
webpack : (config, options) => {
config.module.rules.push({
test : /\.js$/,
exclude : /(node_modules|bower_components)/,
use : [
options.defaultLoaders.babel,
{
loader : 'babel-loader',
query : {
presets : ['next/babel'],
plugins : [
[
BabelPluginTransformImports,
{
// configs ...
},
],
],
},
},
],
});
return config;
},
});
my .babelrc file
{
"presets": [
[
"next/babel",
{
"preset-env": {
"targets": {
"node": "true"
}
}
}
]
],
"plugins": [
[
"module-resolver",
{
"root": ["./"],
"alias": {
"shared": "./src/shared",
"assets": "./src/assets"
}
}
],
["@babel/plugin-proposal-class-properties"],
["@babel/plugin-proposal-optional-chaining"],
["@babel/plugin-proposal-nullish-coalescing-operator"],
],
"env": {
"development": {
"plugins": ["inline-dotenv"],
"presets" : [
[
"@babel/env",
{
"useBuiltIns": "usage",
"corejs": "3.4.7",
"targets": {
"browsers": ["ie >= 11"]
}
}
]
]
},
"production": {
"plugins": [
"transform-inline-environment-variables",
[
"transform-react-remove-prop-types",
{
"mode": "remove",
"removeImport": true
}
]
],
"presets" : [
[
"@babel/env",
{
"useBuiltIns": "usage",
"corejs": "3.4.7",
"targets": {
"browsers": ["ie >= 11"]
}
}
]
]
},
"test": {
"plugins": ["inline-dotenv",
["css-modules-transform", {
"generateScopedName": "[local]___[hash:base64:5]",
"extensions": [".css"]
}]
]
}
}
}
I believe there is a conflict between next.config and babelrc with 'next/babel'. I deleted presets: ['next/babel'] but get same error.
@sebaveg yeah same here 🖐 Next version 9.0.2 works fine, but starting from version 9.0.3 onwards I see this problem
I basically have a custom document component pages/_document.js
, and the error looks like:
TypeError: Class constructor Document cannot be invoked without 'new'
When I disabled/comment my config.module.rules.push in next.config.js and add target.node: 'current' in .baberc then the app run correctly. Check this comment 9000
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
Bug report
TypeError: Class constructor App cannot be invoked without 'new'
Describe the bug
After upgrade to next.js9, my app can't get compiled correctly, and here is the error message
Expected behavior
My app get compiled correctly
System information
Additional context
my .babelrc file