Closed octalpixel closed 2 years ago
Thanks for reporting!
Can you share your next.config.js please?
@Pagebakers my bad, I should have mentioned that setup as well. this project is a nx monorepo
Link to withNx - https://github.com/nrwl/nx/blob/master/packages/next/plugins/with-nx.ts
I created a new project yesterday with Next 12.6, Chakra 2.1 and Saas UI 1.0.0-rc.3 and it's working perfectly, tried again just now without issues.
Might be NX related, I'll try to add it to the project and see what happens :)
I created a new nx project, but nx cli isn't working, only getting empty output. I'll need to dive into it tomorrow.
By the way, this is the project I mentioned, it should run without issues: https://github.com/saas-js/saas-ui-next-blog
Ok did get it running just now with nx.
Not having any issues, not sure how to reproduce your issue.
import { AppProps } from 'next/app';
import Head from 'next/head';
import './styles.css';
import { SaasProvider, theme } from '@saas-ui/react';
import { Container } from '@chakra-ui/react';
function CustomApp({ Component, pageProps }: AppProps) {
return (
<SaasProvider theme={theme}>
<Head>
<title>Welcome to blog-nx!</title>
</Head>
<Container>
<Component {...pageProps} />
</Container>
</SaasProvider>
);
}
export default CustomApp;
{
"name": "blog-nx",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"start": "nx serve",
"build": "nx build",
"test": "nx test"
},
"private": true,
"dependencies": {
"@emotion/react": "11.9.0",
"@emotion/server": "11.4.0",
"@emotion/styled": "11.8.1",
"@chakra-ui/react": "^2.1.2",
"@saas-ui/react": "1.0.0-rc.3",
"framer-motion": "^6",
"@nrwl/next": "14.1.9",
"core-js": "^3.6.5",
"next": "12.1.5",
"react": "18.1.0",
"react-dom": "18.1.0",
"regenerator-runtime": "0.13.7",
"tslib": "^2.3.0"
},
"devDependencies": {
"@emotion/babel-plugin": "11.9.2",
"@nrwl/cli": "14.1.9",
"@nrwl/cypress": "14.1.9",
"@nrwl/eslint-plugin-nx": "14.1.9",
"@nrwl/jest": "14.1.9",
"@nrwl/linter": "14.1.9",
"@nrwl/react": "14.1.9",
"@nrwl/web": "14.1.9",
"@nrwl/workspace": "14.1.9",
"@testing-library/react": "13.1.1",
"@types/jest": "27.4.1",
"@types/node": "16.11.7",
"@types/react": "18.0.8",
"@types/react-dom": "18.0.3",
"@typescript-eslint/eslint-plugin": "~5.18.0",
"@typescript-eslint/parser": "~5.18.0",
"babel-jest": "27.5.1",
"cypress": "^9.1.0",
"eslint": "~8.12.0",
"eslint-config-next": "12.1.5",
"eslint-config-prettier": "8.1.0",
"eslint-plugin-cypress": "^2.10.3",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-jsx-a11y": "6.5.1",
"eslint-plugin-react": "7.29.4",
"eslint-plugin-react-hooks": "4.5.0",
"jest": "27.5.1",
"nx": "14.1.9",
"prettier": "^2.5.1",
"react-test-renderer": "18.1.0",
"ts-jest": "27.1.4",
"ts-node": "9.1.1",
"typescript": "~4.6.2"
}
}
``
I had similar issues as you with Storybook and had to add this to the webpack config.
config.module.rules.push({
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto',
})
Thanks @Pagebakers for looking into it and for the examples. Let me try your suggestions and see if I can fix it.
Let me know how it goes.
@octalpixel Did you get it running?
Hey! Not yet, I went with only chakra for now. But will be revisiting this.
Closing this for now, happy to help you out when you get back to it!
Had same error, tried to recreate it and it happens on fresh NextJS install. Here is a repo: https://github.com/msnegurski/test-saas-ui
Thanks @msnegurski I will look into it!
I'm able to reproduce it finally :)
Next.js fails to resolve to the Chakra UI module correctly, from the Saas UI esm module.
This only happens in JS mode, in TypeScript this doesn't happen it seems.
The problem is the exports definition in the Saas UI packages.
"exports": {
".": {
"require": "./dist/index.js",
"default": "./dist/index.modern.mjs"
}
},
Next.js is tripping over this and fails to resolve sub packages incorrectly. Changing default
to import
fixes the issue. I'm not sure if this is supposed to work like this, or if this is a bug in Next, but I suspect the latter.
I'll release an update asap.
The work around for now is to use Typescript.
I guess time to migrate to typescript. Thanks for the update!
I opened an issue at next.
Released @saas-ui/react@1.3.1 and @saas-ui/pro@0.7.0 with updated exports definitions.
This fixed it for me.
Yes, that fixed it, thank you! Though I am now getting similar error when use pro components like AppShell, Page, Section:
SyntaxError: Named export 'getStateColors' not found. The requested module '@saas-ui/theme' is a CommonJS module, which may not support all module.exports as named exports. CommonJS modules can always be imported via the default export, for example using:
import pkg from '@saas-ui/theme'; const { getStateColors } = pkg;
Interesting, I implemented the same fix in @saas-ui/pro@0.7.0
Let me test this again.
Here is a repo https://github.com/msnegurski/test-next-typescript
.mjs files are causing the issues, I renamed everything to .js to resolve the issue for now.
@Pagebakers arrived here from Google. I don't use Saas-ui but I do use:
"@chakra-ui/icons": "^2.0.1",
"@chakra-ui/pro-theme": "^0.0.53",
"@chakra-ui/react": "^2.0.2",
"@chakra-ui/theme": "^2.0.1",
"@chakra-ui/theme-tools": "^2.0.0",
"next": "12.1.6",
This issue started suddently yesterday in my project and happens only when I use the pro-theme into extendTheme().
Quite don't understand why is the bug, since I didn't update anything. Should be an issue with chakra, actually?
Btw, Love saas-ui, will try!
@tecoad Can you share your error? then we can have a better idea if this is really the same issue.
And please do, love to hear your feedback 👌
Interesting, this issue is the same, I just checked the pro-theme source code and it is using .mjs extension too.
Please upvote and share your issues on the Next issue that I've opened
I opened an issue at next.
@Pagebakers Here is my log:
info - Collecting page data .node:internal/process/promises:279
triggerUncaughtException(err, true /* fromPromise */);
^
file:///Users/matheus/Desktop/project/app/node_modules/@chakra-ui/pro-theme/dist/index.mjs:20
import { extendTheme, theme as theme$1 } from "@chakra-ui/react";
^^^^^
SyntaxError: Named export 'theme' not found. The requested module '@chakra-ui/react' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from '@chakra-ui/react';
const { extendTheme, theme: theme$1 } = pkg;
at ModuleJob._instantiate (node:internal/modules/esm/module_job:128:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:194:5)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
at async importModuleDynamicallyWrapper (node:internal/vm/module:437:15) {
type: 'SyntaxError'
}
I haven't upgraded nextjs recently... which is odd.
Thats odd indeed! This might have been around for awhile though.
Are you using typescript?
@Pagebakers Yes, im using TS. Is is a nextjs or a chakra issue? Im trying to reproduce my case on codesandbox.
Odd, i didnt have the problem in ts projects.
What package manager do you use
@Pagebakers , using yarn
Here is a minimal case I was able to reproduce the same error, if it helps: https://github.com/tecoad/my-app
I will submit this to chakra aswell.
https://github.com/chakra-ui/chakra-ui/issues/6436
Can you reproduce the error in my repo?
Can you try setting this to true or false in next.config.js and see if that resolves anything?
experimental.esmExternals: false
Ok I can confirm setting it to false is working here. But obviously not a solution, because it'll use CJS instead of ESM.. ;/
Same here. Not a solution indeed.
@Pagebakers been seeing the Saas-ui docs, seems very promising. Is there any demo boilerplate where we can see any fully working example? The components are great, but would be nicer to see how the can come together.
Regards,
Here is a live demo, but the complete boilerplate is only available in Pro at the moment.
Came across the issue using the "@saas-ui/react": "^1.0.0-rc.3" on next.js.
The ideal step to reproduce would be to install @chakra/react v2 and the RC release of @saas-ui Edit: This is a nx monorepo