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

Transpile imports if module has module.exports (#5780)

Fixes #5778
Fixes #3650
This commit is contained in:
Tim Neutkens 2018-11-30 17:56:07 +01:00 committed by GitHub
parent 633dd87b18
commit e5002234d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 1 deletions

View file

@ -21,7 +21,7 @@ module.exports = babelLoader.custom(babel => {
return { loader, custom }
},
config (cfg, {customOptions: {isServer, dev}}) {
config (cfg, {source, customOptions: {isServer, dev}}) {
const options = Object.assign({}, cfg.options)
if (cfg.hasFilesystemConfig()) {
for (const file of [cfg.babelrc, cfg.config]) {
@ -37,6 +37,11 @@ module.exports = babelLoader.custom(babel => {
options.presets = [...options.presets, presetItem]
}
if (source.match(/module\.exports/)) {
options.plugins = options.plugins || []
options.plugins.push(commonJsItem)
}
options.overrides = [
...(options.overrides || []),
{

View file

@ -0,0 +1,3 @@
module.exports = async function () {
return 'test'
}

View file

@ -0,0 +1,12 @@
import test from '../lib/async-function'
function ReadOnlyObjectError () {
return 'this is just a placeholder component'
}
ReadOnlyObjectError.getInitialProps = async () => {
const result = await test()
return {result}
}
export default ReadOnlyObjectError

View file

@ -732,5 +732,17 @@ export default (context) => {
}
})
})
it('should not error on module.exports + polyfills', async () => {
let browser
try {
browser = await webdriver(context.appPort, '/read-only-object-error')
expect(await browser.elementByCss('body').text()).toBe('this is just a placeholder component')
} finally {
if (browser) {
browser.close()
}
}
})
})
}