-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for "type": "module" in package.json (#33637)
- [x] Add failing test for development / production - [x] Add failing test for client-side JavaScript - [x] Write `.next/package.json` with `"type": "commonjs" - [x] Fix issue with client-side JavaScript showing `module` is not defined Production works after these changes. Development breaks on module not existing because of the Fast Refresh loader. Working with @sokra to add alternatives to what is being used in the loader to webpack so that it can be updated. Fixes #23029, Fixes #24334 ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [x] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `yarn lint`
- Loading branch information
1 parent
127f94d
commit 62b1704
Showing
5 changed files
with
92 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { createNext } from 'e2e-utils' | ||
import { NextInstance } from 'test/lib/next-modes/base' | ||
import { hasRedbox, renderViaHTTP } from 'next-test-utils' | ||
import webdriver from 'next-webdriver' | ||
|
||
describe('Type module interop', () => { | ||
let next: NextInstance | ||
|
||
beforeAll(async () => { | ||
next = await createNext({ | ||
files: { | ||
'pages/index.js': ` | ||
export default function Page() { | ||
return <p>hello world</p> | ||
} | ||
`, | ||
}, | ||
dependencies: {}, | ||
}) | ||
const contents = await next.readFile('package.json') | ||
const pkg = JSON.parse(contents) | ||
await next.patchFile( | ||
'package.json', | ||
JSON.stringify({ | ||
...pkg, | ||
type: 'module', | ||
}) | ||
) | ||
}) | ||
afterAll(() => next.destroy()) | ||
|
||
it('should render server-side', async () => { | ||
const html = await renderViaHTTP(next.url, '/') | ||
expect(html).toContain('hello world') | ||
}) | ||
|
||
it('should render client-side', async () => { | ||
const browser = await webdriver(next.url, '/') | ||
expect(await hasRedbox(browser)).toBe(false) | ||
await browser.close() | ||
}) | ||
}) |