Skip to content

Commit f2aa14e

Browse files
committed
fix: resolve ESLint parsing and styling errors in code blocks
1 parent ad93cca commit f2aa14e

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

src/content/guides/ecma-script-modules.mdx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,14 @@ W> Avoid top-level await in your entry point when targeting the **browser**. It
125125
```js
126126
// user.js (async ESM module)
127127
const response = await fetch("/api/user");
128+
128129
export const user = await response.json();
129130
```
130131
131132
```js
132133
// index.js - importing an async module works as expected
133134
import { user } from "./user.js";
135+
134136
console.log(user.name);
135137
```
136138
@@ -139,11 +141,11 @@ console.log(user.name);
139141
Imports in ESM are resolved more strictly. Relative requests must include a file extension (e.g. `*.js` or `*.mjs`) following the Node.js convention when the file is flagged as ESM:
140142
141143
```js
144+
// will fail - missing extension
145+
import { helper as missingExt } from "./utils";
146+
142147
// correct in ESM
143148
import { helper } from "./utils.js";
144-
145-
// will fail - missing extension
146-
import { helper } from "./utils";
147149
```
148150
149151
T> Requests to packages e.g. `import "lodash"` are still supported.
@@ -174,15 +176,15 @@ When importing from a CommonJS module inside ESM, only the `default` export
174176
is available (the entire `module.exports` object):
175177
176178
```js
177-
// cjs-module.js (CommonJS)
178-
module.exports = { foo: 1, bar: 2 };
179-
180179
// esm-consumer.js (ESM)
181180
import cjs from "./cjs-module.js";
182-
console.log(cjs.foo); // works - cjs is the whole exports object
183-
184181
// named imports from CJS don't work
185182
import { foo } from "./cjs-module.js"; // undefined
183+
184+
// cjs-module.js (CommonJS)
185+
module.exports = { foo: 1, bar: 2 };
186+
187+
console.log(cjs.foo); // works - cjs is the whole exports object
186188
```
187189
188190
This strict behavior applies when webpack treats the **imported** module as CommonJS.

0 commit comments

Comments
 (0)