Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node_modules breaks build in Visual Studio

Working to add Angular (v4) to an existing ASP.NET MVC 4 application. One of the projects it has includes Selenium Web Driver which has a web.config file included.

node_modules\selenium-webdriver\lib\test\data\web.config

This folder is NOT included in the project but is in my web application folder

myapplication\node_modules
myapplication\Controllers
myapplication\Views
myapplication\web.config
etc...

The web.config in the selenium-webdriver folder causes the build to break with the following error:

It is an error to use a section registered as

allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.

Pretty common error and easily fixed when it is your own mistake, but since this is a library I'm using I don't have control over the file. So my question is a bit leveled based on my research:

  • Can I make the "test" folder of selenium-webdriver go somewhere else?
  • Should my node_modules folder not be at the root of my web application?
  • In general.. how do I fix this?
like image 238
Clarence Klopfstein Avatar asked May 15 '17 15:05

Clarence Klopfstein


2 Answers

install the rimraf package

 npm install rimraf

then in package.json use rimraf command

 'script': {
    'postinstall': 'rimraf node_modules/**/web.config'
 }

Please note that first time you will have to delete it manually, as the package is already installed and postinstall command will not run.

But for all your future installs + for your teammates, it will be taken care of automatically as postinstall command runs after every npm install

Please do read more about npm pre & post hooks

like image 59
harishr Avatar answered Nov 09 '22 01:11

harishr


Its more of a work-around, but my making your node_modules folder hidden it won't show up in your solution explorer and Visual Studio will run your project as normal. As far as I could see, this doesn't affect running your web application.

like image 26
Erwin Bergervoet Avatar answered Nov 09 '22 00:11

Erwin Bergervoet