Angular Universal:找不到模块 server.js

时间:2021-06-01 12:54:15

标签: angular webpack angular-universal

所以在解决了许多错误之后,我仍然不断收到这个错误,它说它在构建后找不到模块 server.js。提供应用程序时失败。

构建 ssr 命令:

npm run build:client-and-server-bundles:prod --verbose && npm run webpack:server --verbose

"build:client-and-server-bundles:prod": "node --max_old_space_size=8000 ./node_modules/@angular/cli/bin/ng run jlg-sources:browser:production && node --max_old_space_size=8000 ./node_modules/@angular/cli/bin/ng run jlg-sources:server:production"

"webpack:server": "webpack --config webpack.server.config.js --progress --colors"

webpack.server.config.js:

const path = require('path');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
  mode: 'none',
  entry: {
    server: './server.ts',
    'server-local': './server.local.ts'
  },
  target: 'node',
  resolve: { extensions: ['.ts', '.js'] },
  optimization: {
    minimize: false
  },
  output: {
    // Puts the output at the root of the dist folder
    path: path.join(__dirname, 'dist'),
    filename: '[name].js'
  },
  module: {
    rules: [
      { test: /\.ts$/, loader: 'ts-loader' },
      {
        // Mark files inside `@angular/core` as using SystemJS style dynamic imports.
        // Removing this will cause deprecation warnings to appear.
        test: /(\\|\/)@angular(\\|\/)core(\\|\/).+\.js$/,
        parser: { system: true },
      },
      {
        test: /hammerjs/,
        loader: "bundle-loader",
        options: {
          lazy: true
        }
      }
    ]
  },
  plugins: [
    new webpack.ContextReplacementPlugin(
      // fixes WARNING Critical dependency: the request of a dependency is an expression
      /(.+)?angular(\\|\/)core(.+)?/,
      path.join(__dirname, 'src'), // location of your src
      {} // a map of your routes
    ),
    new webpack.ContextReplacementPlugin(
      // fixes WARNING Critical dependency: the request of a dependency is an expression
      /(.+)?express(\\|\/)(.+)?/,
      path.join(__dirname, 'src'),
      {}
    ),
    new CopyWebpackPlugin([
      {from:'ecosystem.config.js',to:''}
    ])
  ]
}

错误:找不到模块'/apps/deploy/current/universal/server.js

所以我 CD 到通用目录和 server.js 和 server.local.js 都在那里..我不知道为什么它说它不是。 server.js 文件内容看起来也不错。

0 个答案:

没有答案