Commit 33b9ebc7 authored by Joe Haddad's avatar Joe Haddad Committed by Tim Neutkens

Add `module` as server fallback main field (#6256)

* Add `module` as server fallback main field

* Test that a module only package can be imported
parent 23c9c0d6
...@@ -189,7 +189,7 @@ export default async function getBaseWebpackConfig (dir, {dev = false, isServer ...@@ -189,7 +189,7 @@ export default async function getBaseWebpackConfig (dir, {dev = false, isServer
[PAGES_DIR_ALIAS]: path.join(dir, 'pages'), [PAGES_DIR_ALIAS]: path.join(dir, 'pages'),
[DOT_NEXT_ALIAS]: distDir [DOT_NEXT_ALIAS]: distDir
}, },
mainFields: isServer ? ['main'] : ['browser', 'module', 'main'] mainFields: isServer ? ['main', 'module'] : ['browser', 'module', 'main']
} }
const webpackMode = dev ? 'development' : 'production' const webpackMode = dev ? 'development' : 'production'
......
module.exports = "I am sometimes found by tooling. I shouldn't be."
{
"name": "module-only-package",
"description": "I'm a hipster package that only ships a module entrypoint.",
"module": "./modern.js"
}
import messageInAPackage from 'module-only-package'
export default () => <p id='messageInAPackage'>{messageInAPackage}</p>
...@@ -35,7 +35,8 @@ describe('Configuration', () => { ...@@ -35,7 +35,8 @@ describe('Configuration', () => {
await Promise.all([ await Promise.all([
renderViaHTTP(context.appPort, '/next-config'), renderViaHTTP(context.appPort, '/next-config'),
renderViaHTTP(context.appPort, '/build-id'), renderViaHTTP(context.appPort, '/build-id'),
renderViaHTTP(context.appPort, '/webpack-css') renderViaHTTP(context.appPort, '/webpack-css'),
renderViaHTTP(context.appPort, '/module-only-component')
]) ])
}) })
afterAll(() => { afterAll(() => {
......
...@@ -33,5 +33,10 @@ export default function ({ app }, suiteName, render, fetch) { ...@@ -33,5 +33,10 @@ export default function ({ app }, suiteName, render, fetch) {
const $ = await get$('/build-id') const $ = await get$('/build-id')
expect($('#buildId').text() === '-') expect($('#buildId').text() === '-')
}) })
test('correctly imports a package that defines `module` but no `main` in package.json', async () => {
const $ = await get$('/module-only-content')
expect($('#messageInAPackage').text() === 'OK')
})
}) })
} }
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