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:
parent
633dd87b18
commit
e5002234d0
|
@ -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 || []),
|
||||
{
|
||||
|
|
3
test/integration/basic/lib/async-function.js
Normal file
3
test/integration/basic/lib/async-function.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
module.exports = async function () {
|
||||
return 'test'
|
||||
}
|
12
test/integration/basic/pages/read-only-object-error.js
Normal file
12
test/integration/basic/pages/read-only-object-error.js
Normal 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
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue