1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Add module as server fallback main field (#6256)

* Add `module` as server fallback main field

* Test that a module only package can be imported
This commit is contained in:
Joe Haddad 2019-02-11 19:39:57 -05:00 committed by Tim Neutkens
parent 23c9c0d624
commit 33b9ebc783
7 changed files with 18 additions and 2 deletions

View file

@ -189,7 +189,7 @@ export default async function getBaseWebpackConfig (dir, {dev = false, isServer
[PAGES_DIR_ALIAS]: path.join(dir, 'pages'),
[DOT_NEXT_ALIAS]: distDir
},
mainFields: isServer ? ['main'] : ['browser', 'module', 'main']
mainFields: isServer ? ['main', 'module'] : ['browser', 'module', 'main']
}
const webpackMode = dev ? 'development' : 'production'

View file

@ -0,0 +1 @@
module.exports = "I am sometimes found by tooling. I shouldn't be."

View file

@ -0,0 +1 @@
export default 'OK'

View file

@ -0,0 +1,5 @@
{
"name": "module-only-package",
"description": "I'm a hipster package that only ships a module entrypoint.",
"module": "./modern.js"
}

View file

@ -0,0 +1,3 @@
import messageInAPackage from 'module-only-package'
export default () => <p id='messageInAPackage'>{messageInAPackage}</p>

View file

@ -35,7 +35,8 @@ describe('Configuration', () => {
await Promise.all([
renderViaHTTP(context.appPort, '/next-config'),
renderViaHTTP(context.appPort, '/build-id'),
renderViaHTTP(context.appPort, '/webpack-css')
renderViaHTTP(context.appPort, '/webpack-css'),
renderViaHTTP(context.appPort, '/module-only-component')
])
})
afterAll(() => {

View file

@ -33,5 +33,10 @@ export default function ({ app }, suiteName, render, fetch) {
const $ = await get$('/build-id')
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')
})
})
}