首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Angular Universal找不到模块

Angular Universal找不到模块
EN

Stack Overflow用户
提问于 2018-05-04 09:33:22
回答 1查看 2.1K关注 0票数 2

我使用angular 5.2.10设置了一个angular通用应用程序,当我尝试用angular cli和server.ts版的webpack构建它时,似乎找不到我的模块。

有效的方法:

代码语言:javascript
复制
ng build -prod --build-optimizer --app 0 

&&

代码语言:javascript
复制
ng build --aot --app 1 --output-hashing=false

不同之处:

代码语言:javascript
复制
webpack --config webpack.config.js --progress --colors

错误:

代码语言:javascript
复制
ERROR in /src/app/util/wnumb.ts
[tsl] ERROR in /src/app/util/wnumb.ts(1,26)
  TS2307: Cannot find module '@angular/core'.

ERROR in /src/app/terms-and-conditions/terms-and-conditions.component.ts
[tsl] ERROR in /src/app/terms-and-conditions/terms-and- 
conditions.component.ts(1,27)
  TS2307: Cannot find module '@angular/core'.

ERROR in /src/app/terms-and-conditions/terms-and-conditions.component.ts
[tsl] ERROR in /src/app/terms-and-conditions/terms-and- 
conditions.component.ts(2,24)
  TS2307: Cannot find module '@angular/router'.

我的webpack.config.js文件:

代码语言:javascript
复制
const path = require('path');
const webpack = require('webpack');

module.exports = {
  entry: { server: './src/server.ts' },
  resolve: { extensions: ['.js','.ts'] },
  target: 'node',
  // this makes sure we include node_modules and other 3rd party libraries
  externals: [/(node_modules|main\..*\.js)/],
  output: {
    path: path.join(__dirname, 'dist'),
    filename: '[name].js'
  },
  module: {
    rules: [{ test: /\.ts$/, loader: 'ts-loader' }]
  },
  plugins: [
    new webpack.ContextReplacementPlugin(
      /(.+)?angular(\\|\/)core(.+)?/,
      path.join(__dirname, 'src'), // location of your src
      {} // a map of your routes
    ),
    new webpack.ContextReplacementPlugin(
      /(.+)?express(\\|\/)(.+)?/,
      path.join(__dirname, 'src'),
      {}
    )
  ]
};

和我的tsconfig.json:

代码语言:javascript
复制
{
  "compilerOptions": {
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "mapRoot": "./src/",
    "removeComments": true,
    "sourceMap": true,
    "target": "es2017",
    "typeRoots": [
      "./node_modules/@types"
    ]
  }
}

注意:如有任何帮助,我们将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2018-05-04 10:10:54

如果其他人遇到这个问题,它看起来像是在我的tsconfig.json文件中添加了以下内容来修复它:

代码语言:javascript
复制
"moduleResolution": "node",

tsconfig.json:

代码语言:javascript
复制
{
  "compilerOptions": {
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "mapRoot": "./src/",
    "moduleResolution": "node",
    "removeComments": true,
    "sourceMap": true,
    "target": "es2017",
    "typeRoots": [
      "./node_modules/@types"
    ]
  }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50165913

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档