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

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

Fixes #5778
Fixes #3650
parent 633dd87b
...@@ -21,7 +21,7 @@ module.exports = babelLoader.custom(babel => { ...@@ -21,7 +21,7 @@ module.exports = babelLoader.custom(babel => {
return { loader, custom } return { loader, custom }
}, },
config (cfg, {customOptions: {isServer, dev}}) { config (cfg, {source, customOptions: {isServer, dev}}) {
const options = Object.assign({}, cfg.options) const options = Object.assign({}, cfg.options)
if (cfg.hasFilesystemConfig()) { if (cfg.hasFilesystemConfig()) {
for (const file of [cfg.babelrc, cfg.config]) { for (const file of [cfg.babelrc, cfg.config]) {
...@@ -37,6 +37,11 @@ module.exports = babelLoader.custom(babel => { ...@@ -37,6 +37,11 @@ module.exports = babelLoader.custom(babel => {
options.presets = [...options.presets, presetItem] options.presets = [...options.presets, presetItem]
} }
if (source.match(/module\.exports/)) {
options.plugins = options.plugins || []
options.plugins.push(commonJsItem)
}
options.overrides = [ options.overrides = [
...(options.overrides || []), ...(options.overrides || []),
{ {
......
module.exports = async function () {
return 'test'
}
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
...@@ -732,5 +732,17 @@ export default (context) => { ...@@ -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()
}
}
})
}) })
} }
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