首页 > Web开发 > 详细

解决nextjs部署到now上之后出现的“Unable to import module 'now__launcher'”错误

时间:2019-01-12 16:29:09      阅读:164      评论:0      收藏:0      [点我收藏+]

解决nextjs部署到now上之后出现的“Unable to import module ‘now__launcher‘”错误

这个错误是由于在next.config.js中直接引用了withLess之类的插件导致的。在now环境下require插件需要在PHASE_PRODUCTION_SERVER阶段下,如果不加这个阶段的判断就会报错。

这个是错误的做法

// ? Don‘t put this here

const withCSS = require(‘@zeit/next-css‘); // 由于不在PHASE_PRODUCTION_SERVER阶段所以报错

const { PHASE_PRODUCTION_SERVER } =

  process.env.NODE_ENV === ‘development‘

    ? {}

    : !process.env.NOW_REGION

      ? require(‘next/constants‘)

      : require(‘next-server/constants‘);

module.exports = (phase, { defaultConfig }) => {

  if (phase === PHASE_PRODUCTION_SERVER) {

    // Config used to run in production.

    return {};

  }

 

  return withCSS();

};

 

 

正确的写法:

const { PHASE_PRODUCTION_SERVER } =

  process.env.NODE_ENV === ‘development‘

    ? {}

    : !process.env.NOW_REGION

      ? require(‘next/constants‘)

      : require(‘next-server/constants‘);

module.exports = (phase, { defaultConfig }) => {

  if (phase === PHASE_PRODUCTION_SERVER) {

    // Config used to run in production.

    return {};

  }

 

  // ? Put the require call here.

  const withCSS = require(‘@zeit/next-css‘);

 

  return withCSS();

};

 

 

参考:https://github.com/zeit/next.js/issues/5750

 

解决nextjs部署到now上之后出现的“Unable to import module 'now__launcher'”错误

原文:https://www.cnblogs.com/axel10/p/10260086.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!