3

So, I'm new to ASP.NET MVC.

I have a web application in ASP.NET MVC and I'm trying to add react-bootstrap to it. It's already using React/ReactDOM.

I did

         npm install --save react-bootstrap

and react-bootstrap is in the node_modules folder in the project.

I added react-bootstrap to the dependencies in the Package.json file.

         "dependencies": {
           ......
           "react-bootstrap": "^0.30.0"
         }, 

I added react-bootstrap to the externals in the webpack.config.js file.

        externals:
        {
         'react-bootstrap':
           {
            "var": 'ReactBootstrap',
            web: 'ReactBootstrap',
            root: 'ReactBootStrap',
            commonjs2: 'ReactBootstrap',
            commonjs: 'ReactBootstrap',
            amd: 'ReactBoostrap'
           },
        .....
        }

In the Layout.cshtml, I did added a script tag with the src attribute specifying the location of the reactbootstrap.js file in node_modules folder.

        <script src="@Url.Content("~/node_modules/react-bootstrap/dist/react-bootstrap.min.js")"></script>

But when I do

       import * as ReactBootStrap from 'react-bootstrap';

in the Dashboard.tsx file, it says it can't find the module.

What's missing?

2 Answers 2

1

Try this: npm i @types/react-bootstrap --save

Sign up to request clarification or add additional context in comments.

2 Comments

the output on the command line was @types/[email protected] node_modules\@types\react-bootstrap
@typesreact/[email protected]
0

So, I figured this out. To add another package, TypeScript requires the addition of a declaration file. These typically carry extension of .d.ts, and define prototypes of functions, classes, interfaces, etc. within the package you are adding. In the past, these needed to be created manually, but lately npm-based packages can be handled by new Typescript. There is also a repository of commonly-used Typescript declaration files (NuGet and DefinitelyTyped)

In the package manager console in Visual Studio, you do

Install-Package react-bootstrap.TypeScript.DefinitelyTyped

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.