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 { join } from 'path'
import { posix, join } from 'path'
import { stringify } from 'querystring'
import { API_ROUTE, DOT_NEXT_ALIAS, PAGES_DIR_ALIAS } from '../lib/constants'
import { __ApiPreviewProps } from '../next-server/server/api-utils'
......@@ -103,8 +103,8 @@ export function createEntrypoints(
const bundleFile = normalizePagePath(page)
const isApiRoute = page.match(API_ROUTE)
const clientBundlePath = join('static', 'pages', bundleFile)
const serverBundlePath = join('pages', bundleFile)
const clientBundlePath = posix.join('static', 'pages', bundleFile)
const serverBundlePath = posix.join('pages', bundleFile)
const isLikeServerless = isTargetLikeServerless(target)
......
......@@ -234,14 +234,16 @@ export default async function getBaseWebpackConfig(
// Backwards compatibility
'main.js': [],
[CLIENT_STATIC_FILES_RUNTIME_MAIN]:
`.${path.sep}` +
path.relative(
dir,
path.join(
NEXT_PROJECT_ROOT_DIST_CLIENT,
dev ? `next-dev.js` : 'next.js'
`./` +
path
.relative(
dir,
path.join(
NEXT_PROJECT_ROOT_DIST_CLIENT,
dev ? `next-dev.js` : 'next.js'
)
)
),
.replace(/\\/g, '/'),
[CLIENT_STATIC_FILES_RUNTIME_POLYFILLS]: path.join(
NEXT_PROJECT_ROOT_DIST_CLIENT,
'polyfills.js'
......@@ -1016,6 +1018,13 @@ export default async function getBaseWebpackConfig(
delete webpackConfig.output?.futureEmitAssets
// No longer polyfills Node.js modules:
if (webpackConfig.node) delete webpackConfig.node.setImmediate
if (dev) {
if (!webpackConfig.optimization) {
webpackConfig.optimization = {}
}
webpackConfig.optimization.usedExports = false
}
}
webpackConfig = await buildConfiguration(webpackConfig, {
......
......@@ -34,7 +34,7 @@ function isLikelyASyntaxError(message) {
function formatMessage(message) {
// TODO: Replace this once webpack 5 is stable
if (typeof message === 'object' && message.message) {
message = message.message
message = (message.file ? message.file + '\n' : '') + message.message
}
let lines = message.split('\n')
......
......@@ -2,7 +2,7 @@ import { getOverlayMiddleware } from '@next/react-dev-overlay/lib/middleware'
import { NextHandleFunction } from 'connect'
import { IncomingMessage, ServerResponse } from 'http'
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 webpack from 'webpack'
import { createEntrypoints, createPagesMapping } from '../build/entries'
......@@ -260,11 +260,11 @@ export default class HotReloader {
let additionalClientEntrypoints: { [file: string]: string } = {}
additionalClientEntrypoints[CLIENT_STATIC_FILES_RUNTIME_AMP] =
`.${sep}` +
`./` +
relativePath(
this.dir,
join(NEXT_PROJECT_ROOT_DIST_CLIENT, 'dev', 'amp-dev')
)
).replace(/\\/g, '/')
additionalClientEntrypoints[
CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH
......
......@@ -167,8 +167,8 @@ export default function onDemandEntryHandler(
pageUrl = pageUrl === '' ? '/' : pageUrl
const bundleFile = normalizePagePath(pageUrl)
const serverBundlePath = join('pages', bundleFile)
const clientBundlePath = join('static', 'pages', bundleFile)
const serverBundlePath = posix.join('pages', bundleFile)
const clientBundlePath = posix.join('static', 'pages', bundleFile)
const absolutePagePath = pagePath.startsWith('next/dist/pages')
? require.resolve(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