相关疑难解决方法(0)

如何使用捆绑中的 node_modules 依赖项正确构建用于生产的 NestJS 应用程序?

Afternest buildnest build --webpackdist 文件夹不包含所有必需的模块,我Error: Cannot find module '@nestjs/core'在尝试运行node main.js.

我在https://docs.nestjs.com/上找不到任何关于如何正确构建生产应用程序的明确说明,所以也许我错过了什么?

javascript node.js typescript webpack nestjs

15
推荐指数
3
解决办法
8393
查看次数

SyntaxError:意外的令牌导入typeORM实体

所以,我正在使用typeORM,当我将TypeScript转换为JavaScript时,我遇到了一个奇怪的错误.我收到以下错误:

(function (exports, require, module, __filename, __dirname) { import { Entity, PrimaryGeneratedColumn, ManyToOne, OneToMany, TreeChildren, TreeParent, JoinColumn, Column, Tree, TreeLevelColumn } from "typeorm";
                                                              ^^^^^^

SyntaxError: Unexpected token import
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Function.PlatformTools.load (C:\Users\*redacted*\Workspace\experimental\*redacted*\node_modules\typeorm\platform\PlatformTools.js:126:28)
Run Code Online (Sandbox Code Playgroud)

我的tsconfig.json:

{
    "compilerOptions": {
        "lib": [
           "es5",
           "es6"
        ],
        "target": "es5",
        "module": "commonjs",
        "moduleResolution": "node",
        "outDir": "./build",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "sourceMap": …
Run Code Online (Sandbox Code Playgroud)

typescript typeorm

13
推荐指数
2
解决办法
7479
查看次数

带有 NestJS + Typescript + Webpack + node_modules 的单个文件包

如何?我如何捆绑 NestJS 项目,包括用于离线应用的 node_module?

webpack.config.js

const path = require('path');

module.exports = {
  entry: path.join(__dirname, 'dist/main.js'),
  target: 'node',
  output: {
    filename: 'compiled.js',
    path: __dirname,
  },
  resolve: {
    alias: {
      node_modules: path.join(__dirname, 'node_modules'),
    },
    extensions: ['.js'],
  },
};
Run Code Online (Sandbox Code Playgroud)

包.json

{
  "name": "kai-brs",
  "version": "0.9.1",
  "author": "Sovgut Sergey",
  "private": true,
  "scripts": {
    "build:webpack": "rimraf dist && tsc -p tsconfig.build.json && webpack dist/main.js -o dist/main.bundle.js --mode=production",
    "build": "tsc -p tsconfig.build.json",
    "format": "prettier --write \"src/**/*.ts\"",
    "start": "ts-node -r tsconfig-paths/register src/main.ts",
    "start:dev": "nodemon",
    "start:debug": "nodemon --config …
Run Code Online (Sandbox Code Playgroud)

javascript node.js typescript webpack nestjs

10
推荐指数
1
解决办法
4311
查看次数

如何将 Nestjs 应用程序与 webpack 捆绑在一起

我有一个 Nestjs 应用程序,我需要将它与 webpack 捆绑在一起。捆绑包应包含整个脚本和所有文件。所以我创建了我的 webpack 配置:

const webpack = require('webpack');
const path = require('path');

module.exports = {
  entry: {
    backend: './src/index.ts',
  },
  target: 'node',
  module: {
    rules: [
      {
        test: /.ts$/,
        use: 'ts-loader',
      },
      {
        test: /\.(graphql|gql)$/,
        exclude: /node_modules/,
        loader: 'webpack-graphql-loader',
      },
      {
        test: /\.mjs$/,
        include: /node_modules/,
        type: "javascript/auto",
      }
    ],
  },
  externals: ['fsevents'],
  mode: 'production',
  resolve: {
    extensions: ['.ts', '.mjs', '.js', '.json'],
  },
  output: {
    path: path.join(__dirname, 'bundled'),
    library: 'handler',
    libraryTarget: "commonjs2"
  },
  plugins: [
    new webpack.IgnorePlugin({
      checkResource(resource) …
Run Code Online (Sandbox Code Playgroud)

bundling-and-minification webpack nestjs

10
推荐指数
0
解决办法
1万
查看次数

TypeORM + Webpack causes SyntaxError: Unexpected token for entity file

I have set up a pretty plain project with express, node.js and webpack. After installing TypeORM when configuring webpack.config.js it triggers unexpected token error for User.ts in entity folder.

The problem seems to be related to the fact that ormconfig.json is referring to .ts entity files.

Solution in similar threads seems to be using ts-node with some extra parameters, but I am using webpack in this project and executing the bundle file.

index.ts

import 'reflect-metadata';
import { createConnection } from …
Run Code Online (Sandbox Code Playgroud)

node.js typescript webpack typeorm

3
推荐指数
1
解决办法
2176
查看次数