使用NextJS和next-web-worker包时出现未定义的窗口错误。

require('dotenv').config();
const withPlugins = require('next-compose-plugins');
const withCSS = require('@zeit/next-css');
const withWorkers = require('@zeit/next-workers');
const Dotenv = require('dotenv-webpack');

const webpackConfig = (config) => {
  config.plugins = config.plugins || [];
  config.target = 'universal';
  config.output = {
    ...config.output,
    filename: 'bundle.js',
    path: path.join(__dirname, 'dist'),
    globalObject: '(this || global)',
    publicPath: 'http://localhost:3000'
  };

  config.plugins = [
    ...config.plugins,

    // Read the .env file
    new Dotenv({
      path: path.join(__dirname, '.env'),
      systemvars: true
    })
  ];

  return config;
};

module.exports = withPlugins([[withCSS], [withWorkers]], webpackConfig);


推荐的解决方法似乎是将globalObject设置为此或全局,但这不起作用。还有其他解决方法吗?

最佳答案

我只是遇到了同样的错误,可以通过以下the advice here来解决:

yarn add @zeit/next-workers@canary

关于node.js - 未定义NextJS Webworker的窗口,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56203586/

10-11 22:36
查看更多