Having trouble importing the module in NestJS with Swagger?

Currently, I am in the process of developing a boilerplate NestJS application. My goal is to integrate @nestjs/swagger into the project. However, I have encountered an import error while trying to include the module.

npm install --save @nestjs/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6b181c0a0c0c0e192b5f4553455b">[email protected]</a> --force

I attempted the command above after receiving errors. I even tried deleting and reinstalling the node_modules directory, but unfortunately, none of these solutions are resolving the issue.

src/main.ts:2:44 - error TS1005: 'from' expected.

2 import { DocumentBuilder, SwaggerModule }  '@nestjs/swagger'
                                             ~~~~~~~~~~~~~~~~~

[7:47:36 PM] Found 1 error. Watching for file changes.

Below is the content of the main.ts file:

import { NestFactory } from '@nestjs/core';
import { DocumentBuilder, SwaggerModule }  '@nestjs/swagger'
import { AppModule } from './app.module';

import * as cookieParser from 'cookie-parser';


async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  const options = new DocumentBuilder()
    .setTitle('NestJS Middleware Test')
    .setDescription('Implement a simple request interceptor for authorization')
    .setVersion('0.0.1')
    .build();

  const document = SwaggerModule.createDocument(app, options)
  SwaggerModule.setup('api', app, document)

  app.use(cookieParser());
  await app.listen(3000);
}
bootstrap();

Answer №1

You've made a mistake with the way you are importing. The error message clearly shows that it is expecting 'from' in your syntax.

The proper method for importing is

import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountering issues with HTML loading interpolation before constructor in TypeScript

I am currently working on a project using Angular 6 and encountering some challenges. Here is the issue at hand: I am facing an error in the HTML Console, which occurs after reloading the page. The error message indicates that the variable "atual" is unde ...

Best practices for managing backend errors with Next.js 14

Currently, I am developing a project in Next.js 14 and I have set up my API requests using fetch within a handler.tsx file as shown below: async function getPositions() { const response = await fetch( process.env.BASE_API_URL + "/positions?enabl ...

Differences between Typescript compilation: Using dot notation vs square brackets when accessing non-existent properties

Imagine having the given class and code snippet: class myClass{ x: number; } const obj = new myClass(); obj.y = 7; // produces a compile error. Property 'y' does not exist on type myClass. obj['y'] = 7; // compiles without any issu ...

ag-grid's onGridReady function is not functioning properly

I am trying to dynamically load ag-grid when a button is clicked, but I have encountered issues with both of my approaches. Here is my code for the first method: onBtnClick(){ this.gridOptions ={ onGridReady : function(){ console ...

A method to simultaneously retrieve all emitted values from multiple EventEmitters in Angular 7

I am facing a scenario where I have a parent component that consists of multiple child components. Each child component may differ from the others, creating a diverse structure within the parent component. Here's an example: ...

Angular Material's autocomplete feature allows users to easily search

I am currently working on creating an Angular Material Autocomplete feature. At the moment, I have successfully displayed the options and when selected, the correct name is inserted into the input field. However, my next task is to enable filtering of the ...

Currently, I am working on developing a to-do task manager using Angular 2. One of the tasks I am tackling involves updating the value

I'm facing an issue with managing to-do tasks. I would like to update the value of an option in a select dropdown when the (change) event is triggered. There are 2 components: //app.component.ts //array object this.dataArr[this.counter] = {id: this ...

Having trouble running a React JS application on Windows?

Currently, I am using node(12.16.2), npm(6.14.4), and create-react-app(3.4.1). Once I create an app using create-react-app {app name} and navigate to its directory, I attempt to run it with npm start, but encounter the following error message. It seems tha ...

Reduce the size of a container element without using jquery

In my Angular application, I have structured the header as follows: -- Header -- -- Sub header -- -- Search Box -- -- Create and Search Button -- -- Scroll Div -- HTML: <h1> Header </h1> <h3> Sub header </h3> <div class="s ...

Is it recommended to enable caching for either node_modules or $HOME/.npm in Travis?

I'm feeling a bit puzzled about which directory is the best choice for caching. There's recommendations for both options, but no real comparison to help me decide why I should choose one over the other. For example, on their blog, Travis itself ...

Receiving a reply from the axios function

Whenever I try to call the lookUpItem function from ItemSearch.vue, I always get an undefined response. Code snippet from ItemSearch.vue: <script setup lang="ts"> import { lookUpItem } from '../systemApi' async fu ...

The extended class possesses a distinct type from the base class, which is reinforced by an interface

Is it possible to write a method that is an extension of a base class, but with a different return type, if supported by the shared interface, without adding a type declaration in class 'a'? In practical terms, classes a & b exist in JavaScript ...

Issue: Module "mongodb" could not be found when using webpack and typescript

I am encountering an issue while trying to use mongoose with webpack. Even though I have installed it as a dependency, when attempting to utilize the mongoose object and execute commands, it gives me an error stating that it cannot find the "." Module. Thi ...

What is the proper error type to use in the useRouteError() function in react-router-dom?

In my React project, I am utilizing the useRouteError() hook provided by react-router-dom to handle any errors that may arise during routing. However, I'm uncertain about the correct type for the error object returned by this hook. Currently, I have ...

I'm trying to figure out which one is the correct term on Ubuntu - is it "node" or "nodejs"? And

Trying to install webpack-dev-server but it requires the latest version of nodejs. I am using Ubuntu 20.04 and attempted to update with nvm, which did not work. Following this Q&A answer here, I then tried to install nodejs using sudo apt-get install ...

Can anyone guide me on implementing getServerSideProps in a TypeScript NextPage component?

I've come across a page that I'd like to replicate, with the code sourced from https://github.com/dabit3/nextjs-lit-token-gating/blob/main/pages/protected.js: import Cookies from 'cookies' import LitJsSdk from 'lit-js-sdk' ex ...

Is it possible to execute two npm commands simultaneously within a single terminal window?

In my npm scripts, I have set up two commands: "scripts": { "webpack": "webpack --config webpack.config.js --watch", "server": "nodemon server.js", } One command runs webpack every time a file is saved, while the other starts the server using nodemon to ...

Navigating through diverse objects in Typescript

My challenge involves a state object and an update object that will merge with the state object. However, if the update value is null, it should be deleted instead of just combining them using {...a, ...b}. const obj = { other: new Date(), num: 5, ...

Creating a custom type for accepted arguments in a Typescript method

Below is the structure of a method I have: const a = function (...args: any[]) { console.log(args); } In this function, the type of args is any[]. I am looking to create a specific type for the array of arguments accepted by this method in Typescript. ...

Issue encountered during npm installation of node-sass-middleware

After executing the command npm install node-sass-middleware, I encountered an error... npm WARN deprecated @npmcli/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e68b899083cb808f8a83a6d7c8d7c8d4">[email protected]</ ...