最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Import dynamic a typescript file in Next JS - Stack Overflow

programmeradmin0浏览0评论

According NextJs documentation we can use dynamic import for javascripts filesconst DynamicComponent = dynamic(() => import('../ponents/hello')).
Will be correct to use dynamic import also for .tsx file like this:

const MyComponent = dynamic(() => import('main/my-file.tsx'), {
  ssr: false,
});

According NextJs documentation we can use dynamic import for javascripts filesconst DynamicComponent = dynamic(() => import('../ponents/hello')).
Will be correct to use dynamic import also for .tsx file like this:

const MyComponent = dynamic(() => import('main/my-file.tsx'), {
  ssr: false,
});

? Or we can import dynamically only .js files?

Share Improve this question asked Mar 28, 2022 at 12:24 AskingAsking 4,24021 gold badges82 silver badges163 bronze badges 1
  • You can dynamically import both JavaScript and TypeScript modules. – juliomalves Commented Apr 1, 2022 at 22:23
Add a ment  | 

1 Answer 1

Reset to default 5

I guess you can dynamically import ts files in nextjs with some workarounds.

import dynamic from "next/dynamic";
...
...
const Button = dynamic(() => import("../ponents/Button").then(module => module.default));

If you want to read further https://github./vercel/next.js/issues/4515

发布评论

评论列表(0)

  1. 暂无评论