NervJS / tarojs-plugin-ssr

让 Taro H5 支持 Pre-rendering、SSR 和 ISR,极致的首屏速度🚀,利于 SEO🔍

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

能否可以将 next.config.js 改为 next.config.cjs 以适配 es6 module 的 package

dexbol opened this issue · comments

或者直接在 next.config.js 使用 es6 module?

BTW,我尝试了在 onBuildFinish 中将 next.config.js 改为 next.config.cjs ,但从结果上看,在改之前,nextjs 就开始运行并加载配置文件了。

@dexbol 为什么关掉了,是找到解决方法了么?

@dexbol 为什么关掉了,是找到解决方法了么?

找到了,又没有完全找到😄。我的使用场景是这样的:代码库使用 monorepo ,taro 项目与后台项目同在一个 git repo 中。最外层 package.json 和后台的 package.json 都配置为 es module ("type": "module"), 而 Taro 项目必须使用 commonjs 才能跑起来。之前我把 nextjs 的 dist 路径配置为 monorepo/dist/nextjs 。这导致 nextjs 运行时会根据最外层的 package.json (es module)来解析 next.config.js (commonjs) 造成报错。
后来我把 dist 路径改为 monorepo/taro-project/dist 后,nextjs 就按照 commonjs 解析 next.config.js 了。 不过会报另一个错误: Cannot find module 'htmltransform' postcss.config.js 中用的插件。我简单搜索了一下报错,没找到相关 issue。我想可能目前 taro 以及插件对 es module 的兼容不太好,ssr 也不是当前项目急需的功能,就先放弃了,后面再等等升级😄。