-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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(framework): Resolve CJS issues this time with json-schema-faker #6766
Conversation
✅ Deploy Preview for novu-stg-vite-dashboard-poc ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
@novu/client
@novu/framework
@novu/headless
@novu/js
@novu/nextjs
@novu/nest
@novu/node
@novu/notification-center
novu
@novu/providers
@novu/react
@novu/react-native
@novu/shared
@novu/stateless
commit: |
7c18a50
to
aba2de9
Compare
990adf1
to
ac7b5af
Compare
ef941ef
to
d68d18a
Compare
07a77b6
to
659f791
Compare
659f791
to
bdb270d
Compare
Json-schema-faker is causing big HMR and Webpack headaches when @novu/framework is used in Next.js. To address the issue, we decided to go old-school and hardcode the IIFE version of the source code in our package. The code was copied for https://unpkg.com/browse/json-schema-faker@0.5.6/dist/main.iife.js. PLEASE NOTE THE CODE WAS SLIGHTLY MODIFIED TO MAKE IT WORK IN @novu/framework. See the end of this file. See json-schema-faker/json-schema-faker#796 (comment).
bdb270d
to
cb6c2e5
Compare
@@ -1,5 +1,3 @@ | |||
{ | |||
"main": "../dist/cjs/servers/express.cjs", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After careful testing, these are not required as ESM sub-exports will always be fetched from the top-level package.json
@@ -239,7 +239,6 @@ | |||
"better-ajv-errors": "^1.2.0", | |||
"chalk": "^4.1.2", | |||
"cross-fetch": "^4.0.0", | |||
"json-schema-faker": "^0.5.6", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This package is causing a lot of ESM/CJS trouble. It was decided to hardcode its UMD version in the framework.
@@ -37,7 +37,7 @@ | |||
"format:fix": "prettier --write --ignore-path .gitignore .", | |||
"build": "NODE_ENV=production tsup", | |||
"build:watch": "tsup --watch", | |||
"postbuild": "./scripts/copy-package-json.sh && pnpm run check:exports && pnpm check:circulars", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy-package.json is not anymore assuming package exports work correctly. Attw confirms the removal.
|
||
const frameworks: SupportedFrameworkName[] = ['h3', 'express', 'next', 'nuxt', 'sveltekit', 'remix', 'lambda', 'nest']; | ||
|
||
const baseConfig: Options = { | ||
entry: ['src/index.ts', 'src/internal/index.ts', ...frameworks.map((framework) => `src/servers/${framework}.ts`)], | ||
sourcemap: false, | ||
clean: true, | ||
treeshake: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Libraries need to be treeshaken by the host application bundler.
|
||
const frameworks: SupportedFrameworkName[] = ['h3', 'express', 'next', 'nuxt', 'sveltekit', 'remix', 'lambda', 'nest']; | ||
|
||
const baseConfig: Options = { | ||
entry: ['src/index.ts', 'src/internal/index.ts', ...frameworks.map((framework) => `src/servers/${framework}.ts`)], | ||
sourcemap: false, | ||
clean: true, | ||
treeshake: true, | ||
dts: true, | ||
minify: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Libraries shouldn't be minified. The host application bundler should handle that.
However, setting bundle: false
and minify: false
in tsup
config, breaks Nest.js loading @novu/framework.
The hypothesis is that building through ESBuild alone is not enough. Minify triggers a rollup processing that, for some reason, satisfies Nest.js CommonJS requirements.
We will get back to this in a separate PR, as this one is already big enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the detailed explanation. Sounds like a good plan 👍
dts: true, | ||
minify: true, | ||
minifyWhitespace: true, | ||
minifyIdentifiers: true, | ||
minifySyntax: true, | ||
define: { | ||
SDK_VERSION: `"${version}"`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Static code replacements allow us to eliminate importing package.json
on runtime that can cause some CJS/ESM issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! 👍
What changed? Why was the change needed?
Apply more configuration changes for better ESM/CJS support. Also try to remove the Node
https
dependency fromjson-schema-faker
Fixes #6701
Fixes #6332