Webpack无法获取配置路径,路径必须为字符串,接收到空值

时间:2019-07-12 07:09:06

标签: reactjs

我的reactjs网络应用使用webpack,在Mac上它具有正确的配置并且运行良好,但是在窗口上它总是报告为“路径必须是字符串,接收到null”(我认为原因是webpack无法获取配置参数在窗口上),您知道那里有什么问题吗?

  • 我确实尝试过console.log个用于从webpack配置中构建js代码的路径及其返回的正确路径(在窗口上)
  • 我确实尝试运行node_modules/bin/webpack,并且运行正常。

但是似乎它仍然无法获得正确的配置。

  • Package.json:

    "build": "node tools/build",
    
  • tools / build.js:

    // Process CLI arguments
    const argv = process.argv.slice(2);
    const writeStatsJson = argv.indexOf('--stats') !== -1;
    
    if (writeStatsJson) {
        return bfj
               .write(`${paths.appBuild}/bundle-stats.json`, stats.toJson())
               .then(() => resolve(resolveArgs))
               .catch(error => reject(new Error(error)));
    }
    
  • paths.js

module.exports = {
  appPath: resolvePath('.'),
  appAssets: resolvePath('assets'),
  appBuild: resolvePath('build'),
  appHtml: resolvePath('assets/index.html'),
  appIndexJs: resolveModule(resolvePath, 'src/index'),
  appModernizr: resolvePath('src/vendor/modernizr-custom.js'),
  appModernizrrc: resolvePath('src/vendor/modernizrrc.json'),
  appPolyfills: resolvePath('src/polyfills'),
  appSrc: resolvePath('src'),
  config: resolvePath('config'),
  dotenv: resolvePath('.env'),
  nodeModules: resolvePath('node_modules'),
  packageJson: resolvePath('package.json'),
  publicPath: resolvePath('/'),
  test: resolvePath('test'),
  };

-webpack.config.js

output: {
      chunkFilename: isProd ? 'scripts/js/[name].[git-hash].chunk.js' : '[name].chunk.js',
      filename: isProd ? '[name].[git-hash].js' : '[name].js',
      path: paths.appBuild,
      pathinfo: isDev,
      publicPath,
      // Point sourcemap entries to original disk location (format as URL on Windows)
      devtoolModuleFilenameTemplate: isProd
        ? info => path.relative(paths.appSrc, info.absoluteResourcePath).replace(/\\/g, '/')
        : info => path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'),
    },
    resolve: {
      alias: {
        assets: paths.appAssets,
        modernizr$: paths.appModernizrrc,
        test: paths.test,
        'react-dom': '@hot-loader/react-dom',
      },
      modules: [paths.appSrc, paths.nodeModules],
      extensions: ['.js', '.jsx', '.json'],
    }

我做了console.log paths.appBuild它的返回正确的文件夹

0 个答案:

没有答案