next/dynamic not recognizing referenced objects
See original GitHub issueWhat version of Next.js are you using?
12.0.7
What version of Node.js are you using?
16.13.1
What browser are you using?
What operating system are you using?
Windows (Docker Node.js devcontainer)
How are you deploying your application?
Describe the Bug
When using next/dynamic
this way:
const dynamicProps = {
loading: () => <Loading />,
ssr: false,
};
const LoginView = dynamic(
() => import('@/components/auth/LoginView'),
dynamicProps,
);
I get the following error:
Error: error: next/dynamic options must be an object literal.
But just using an spread operator solves the issue:
const dynamicProps = {
loading: () => <Loading />,
ssr: false,
};
const LoginView = dynamic(() => import('@/components/auth/LoginView'), {
...dynamicProps,
});
Seems that SWC
is failing to recognize and transform the variable
Expected Behavior
I expect the app to build and parse correctly the dynamic
options
To Reproduce
const dynamicProps = {
loading: () => <Loading />,
ssr: false,
};
const LoginView = dynamic(
() => import('@/components/auth/LoginView'),
dynamicProps,
);
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Next js dynamic imports with object destucturing
UDFCompatibleDatafeed is a javascript class. I am getting an error. TypeError: UDFCompatibleDatafeed is not a constructor. Seems this is not ...
Read more >How to Use Dynamic Imports in Next.js - WebDevStudios
At the time of writing this, dynamic imports in Next.js are only supported for ... Assign the dynamic function to reference your component....
Read more >Master code splitting with dynamic imports in Next.js - Daily.dev
To import it using the dynamic import() from the src/components/hello. js file, we will use named exports. import dynamic from "next/dynamic"; ...
Read more >Data Fetching: getStaticProps - Next.js
The context parameter is an object containing the following keys: params contains the route parameters for pages using dynamic routes. For example, if...
Read more >Built-in reference types - C# reference - Microsoft Learn
The object type; The string type; The delegate type; The dynamic type ... defined to compare the values of string objects, not references....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I know, as I’ve said in the description you can trick the compiler by spreading the variable. But I don’t think this should be intended behavior
https://nextjs.org/docs/messages/invalid-dynamic-options-type
You can get it working by updating the
Layout.tsx
files dynamic imports to be