Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Build error on project with React TSX
Pepijn Sitter
#1 Posted : Thursday, August 6, 2020 7:31:27 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 8/5/2020(UTC)
Posts: 2
Location: Netherlands

Hi guys,

I've used NCrunch in the past and loved the tool. Started a new project recently where I would like to measure (and introduce to my colleagues) code coverage. Since I have VS Pro I would like to use NCrunch again.

I'm running into a build problem with my current solution. It is an 'integrated' .NET Core SPA (React) solution. Integrated in the sense that they like to use the Microsoft 'Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer' in the .NET Core API project. And use 'services.AddSpaStaticFiles(configuration => configuration.RootPath = "reactapp/build");' to serve the files. I know most people don't work this way, they would use VS Code for running the SPA separately, but the internal guys apparently love this way.

I am however running into an NCrunch problem where the SPA project doesn't build and NCrunch then doesn't work. I get these errors:

reactapp\src\app-common\AppRouter.tsx (1, 50): Build:Cannot find module 'react'.
reactapp\src\app-common\AppRouter.tsx (2, 56): Build:Cannot find module 'react-router-dom'.
reactapp\src\app-common\AppRouter.tsx (35, 14): Build:Property 'state' does not exist on type 'RenderUserRoute'.
reactapp\src\app-common\AppRouter.tsx (45, 18): Build:Property 'setState' does not exist on type 'RenderUserRoute'.
reactapp\src\app-common\AppRouter.tsx (53, 22): Build:Property 'state' does not exist on type 'RenderUserRoute'.
reactapp\src\app-common\AppRouter.tsx (58, 68): Build:Property 'state' does not exist on type 'RenderUserRoute'.
reactapp\src\app-common\AppRouter.tsx (58, 104): Build:Property 'state' does not exist on type 'RenderUserRoute'.
reactapp\src\app-common\AppRouter.tsx (61, 84): Build:Property 'state' does not exist on type 'RenderUserRoute'.
reactapp\src\app-common\AppRouter.tsx (62, 102): Build:Property 'state' does not exist on type 'RenderUserRoute'.
reactapp\src\app-common\AppRouter.tsx (63, 109): Build:Property 'state' does not exist on type 'RenderUserRoute'.
reactapp\src\app-common\AppRouter.tsx (64, 110): Build:Property 'state' does not exist on type 'RenderUserRoute'.

Is there any way I can get NCrunch to work in this case? Maybe exclude the TSX files since I won't be using NCrunch obviously on these files?

Thanks,

Pepijn
Remco
#2 Posted : Thursday, August 6, 2020 7:42:57 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi, thanks for sharing this problem.

I have no experience with this particular package and we haven't done any work to verify it can work with NCrunch. However, there may be a couple of options available to you.

The first option is to try including the referenced files in your NCrunch workspace by adding them to the 'Additional files to include' NCrunch setting. Most likely they aren't being flagged up by MSBuild, so NCrunch doesn't know to copy them to the workspace. By including them like this, they should be in the workspace NCrunch uses for building and it may allow your build to pass as normal.

The second option is to find a way to disable the react build step in your project. This could by done by adding a condition to a build target or adding a conditional property to your build. This might require you to run through the relevant target files to see how you can disable them in the NCrunch build. This documentation page gives an example of how you can add conditional behaviour to your build system so that it behaves differently under NCrunch.
Pepijn Sitter
#3 Posted : Thursday, August 6, 2020 2:45:03 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 8/5/2020(UTC)
Posts: 2
Location: Netherlands

Thanks for your quick answer. I have tried to get he build to work, but I think I need to do an npm restore in the build. Probably a pre build step but as you suggest that is not really a nice option. Will see what I can do. Will try option number 2 now.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.035 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download