Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Bring back ESM build (and fix bundle size) #381

Merged
merged 2 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/next-intl/middleware.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import Middleware from './dist/middleware';
import createMiddleware from './dist/middleware';

export = Middleware;
export = createMiddleware;
13 changes: 13 additions & 0 deletions packages/next-intl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,39 @@
"postpublish": "git checkout . && rm ./README.md"
},
"main": "dist/index.js",
"module": "dist/index.mjs",
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not used by Node.js, only by ESM-enabled bundlers.

"typings": "dist/index.d.ts",
"exports": {
".": {
"react-server": {
"node": "./dist/react-server/index.js",
Copy link
Owner Author

@amannn amannn Jul 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's important that this goes first, so it has priority over import when compiled under Node.js.

We're not 100% ESM-compatible: https://nodejs.org/api/esm.html#esm_mandatory_file_extensions

But we don't want to be ESM-compatible anyway, because Next.js itself isn't, therefore the bundler will crash when it encounters imports from Next.js.

Rather, we want to stay in CJS land for Node.js and only use import when bundling for the browser (webpack).

"import": "./dist/react-server/index.mjs",
"default": "./dist/react-server/index.js"
},
"node": "./dist/index.js",
"import": "./dist/index.mjs",
"default": "./dist/index.js"
},
"./server": {
"node": "./dist/server/index.js",
"import": "./dist/server/index.mjs",
"default": "./dist/server/index.js"
},
"./client": {
"node": "./dist/client/index.js",
"import": "./dist/client/index.mjs",
"default": "./dist/client/index.js"
},
"./link": {
"types": "./link.d.ts",
"node": "./dist/link/index.js",
"import": "./dist/link/index.mjs",
"default": "./dist/link/index.js"
},
"./middleware": {
"types": "./middleware.d.ts",
"node": "./dist/middleware/index.js",
"import": "./dist/middleware/index.mjs",
"default": "./dist/middleware/index.js"
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/next-intl/tsup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {defineConfig} from 'tsup';

export default defineConfig({
entry: ['src'],
format: ['cjs'],
format: ['cjs', 'esm'],
splitting: false,
sourcemap: true,
clean: true,
Expand Down
1 change: 1 addition & 0 deletions packages/use-intl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"prepublishOnly": "CI=true turbo test && turbo lint && turbo build"
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"typings": "dist/index.d.ts",
"files": [
"dist",
Expand Down
2 changes: 1 addition & 1 deletion packages/use-intl/tsup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {defineConfig} from 'tsup';

const config = {
entry: ['src'],
format: ['cjs'],
format: ['cjs', 'esm'],
splitting: false,
sourcemap: true,
clean: true,
Expand Down