Unverified Commit ab4a90b0 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Add filename to error in webpack 5 (#14977)

Co-authored-by: 's avatarTobias Koppers <sokra@users.noreply.github.com>
parent 10408241
import chalk from 'next/dist/compiled/chalk' import chalk from 'next/dist/compiled/chalk'
import { join } from 'path' import { posix, join } from 'path'
import { stringify } from 'querystring' import { stringify } from 'querystring'
import { API_ROUTE, DOT_NEXT_ALIAS, PAGES_DIR_ALIAS } from '../lib/constants' import { API_ROUTE, DOT_NEXT_ALIAS, PAGES_DIR_ALIAS } from '../lib/constants'
import { __ApiPreviewProps } from '../next-server/server/api-utils' import { __ApiPreviewProps } from '../next-server/server/api-utils'
...@@ -103,8 +103,8 @@ export function createEntrypoints( ...@@ -103,8 +103,8 @@ export function createEntrypoints(
const bundleFile = normalizePagePath(page) const bundleFile = normalizePagePath(page)
const isApiRoute = page.match(API_ROUTE) const isApiRoute = page.match(API_ROUTE)
const clientBundlePath = join('static', 'pages', bundleFile) const clientBundlePath = posix.join('static', 'pages', bundleFile)
const serverBundlePath = join('pages', bundleFile) const serverBundlePath = posix.join('pages', bundleFile)
const isLikeServerless = isTargetLikeServerless(target) const isLikeServerless = isTargetLikeServerless(target)
......
...@@ -234,14 +234,16 @@ export default async function getBaseWebpackConfig( ...@@ -234,14 +234,16 @@ export default async function getBaseWebpackConfig(
// Backwards compatibility // Backwards compatibility
'main.js': [], 'main.js': [],
[CLIENT_STATIC_FILES_RUNTIME_MAIN]: [CLIENT_STATIC_FILES_RUNTIME_MAIN]:
`.${path.sep}` + `./` +
path.relative( path
dir, .relative(
path.join( dir,
NEXT_PROJECT_ROOT_DIST_CLIENT, path.join(
dev ? `next-dev.js` : 'next.js' NEXT_PROJECT_ROOT_DIST_CLIENT,
dev ? `next-dev.js` : 'next.js'
)
) )
), .replace(/\\/g, '/'),
[CLIENT_STATIC_FILES_RUNTIME_POLYFILLS]: path.join( [CLIENT_STATIC_FILES_RUNTIME_POLYFILLS]: path.join(
NEXT_PROJECT_ROOT_DIST_CLIENT, NEXT_PROJECT_ROOT_DIST_CLIENT,
'polyfills.js' 'polyfills.js'
...@@ -1016,6 +1018,13 @@ export default async function getBaseWebpackConfig( ...@@ -1016,6 +1018,13 @@ export default async function getBaseWebpackConfig(
delete webpackConfig.output?.futureEmitAssets delete webpackConfig.output?.futureEmitAssets
// No longer polyfills Node.js modules: // No longer polyfills Node.js modules:
if (webpackConfig.node) delete webpackConfig.node.setImmediate if (webpackConfig.node) delete webpackConfig.node.setImmediate
if (dev) {
if (!webpackConfig.optimization) {
webpackConfig.optimization = {}
}
webpackConfig.optimization.usedExports = false
}
} }
webpackConfig = await buildConfiguration(webpackConfig, { webpackConfig = await buildConfiguration(webpackConfig, {
......
...@@ -34,7 +34,7 @@ function isLikelyASyntaxError(message) { ...@@ -34,7 +34,7 @@ function isLikelyASyntaxError(message) {
function formatMessage(message) { function formatMessage(message) {
// TODO: Replace this once webpack 5 is stable // TODO: Replace this once webpack 5 is stable
if (typeof message === 'object' && message.message) { if (typeof message === 'object' && message.message) {
message = message.message message = (message.file ? message.file + '\n' : '') + message.message
} }
let lines = message.split('\n') let lines = message.split('\n')
......
...@@ -2,7 +2,7 @@ import { getOverlayMiddleware } from '@next/react-dev-overlay/lib/middleware' ...@@ -2,7 +2,7 @@ import { getOverlayMiddleware } from '@next/react-dev-overlay/lib/middleware'
import { NextHandleFunction } from 'connect' import { NextHandleFunction } from 'connect'
import { IncomingMessage, ServerResponse } from 'http' import { IncomingMessage, ServerResponse } from 'http'
import { WebpackHotMiddleware } from './hot-middleware' import { WebpackHotMiddleware } from './hot-middleware'
import { join, normalize, relative as relativePath, sep } from 'path' import { join, normalize, relative as relativePath } from 'path'
import { UrlObject } from 'url' import { UrlObject } from 'url'
import webpack from 'webpack' import webpack from 'webpack'
import { createEntrypoints, createPagesMapping } from '../build/entries' import { createEntrypoints, createPagesMapping } from '../build/entries'
...@@ -260,11 +260,11 @@ export default class HotReloader { ...@@ -260,11 +260,11 @@ export default class HotReloader {
let additionalClientEntrypoints: { [file: string]: string } = {} let additionalClientEntrypoints: { [file: string]: string } = {}
additionalClientEntrypoints[CLIENT_STATIC_FILES_RUNTIME_AMP] = additionalClientEntrypoints[CLIENT_STATIC_FILES_RUNTIME_AMP] =
`.${sep}` + `./` +
relativePath( relativePath(
this.dir, this.dir,
join(NEXT_PROJECT_ROOT_DIST_CLIENT, 'dev', 'amp-dev') join(NEXT_PROJECT_ROOT_DIST_CLIENT, 'dev', 'amp-dev')
) ).replace(/\\/g, '/')
additionalClientEntrypoints[ additionalClientEntrypoints[
CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH
......
...@@ -167,8 +167,8 @@ export default function onDemandEntryHandler( ...@@ -167,8 +167,8 @@ export default function onDemandEntryHandler(
pageUrl = pageUrl === '' ? '/' : pageUrl pageUrl = pageUrl === '' ? '/' : pageUrl
const bundleFile = normalizePagePath(pageUrl) const bundleFile = normalizePagePath(pageUrl)
const serverBundlePath = join('pages', bundleFile) const serverBundlePath = posix.join('pages', bundleFile)
const clientBundlePath = join('static', 'pages', bundleFile) const clientBundlePath = posix.join('static', 'pages', bundleFile)
const absolutePagePath = pagePath.startsWith('next/dist/pages') const absolutePagePath = pagePath.startsWith('next/dist/pages')
? require.resolve(pagePath) ? require.resolve(pagePath)
: join(pagesDir, pagePath) : join(pagesDir, pagePath)
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment