7

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?
Clarence Klopfstein
  • 4,682
  • 10
  • 33
  • 47
  • this is what you are looking for: [link](https://stackoverflow.com/questions/9300927/error-to-use-a-section-registered-as-allowdefinition-machinetoapplication-beyo), actually this question is sort of duplicate – harishr Jun 30 '17 at 07:31
  • Not a duplicate at all. I'm 100% aware of how I can fix this by changing default web.config settings. I'm looking for some way with npm to work around this. Based on my bounty being ignored, looks like the only fix is the "hidden" trick below... which kind of sucks. – Clarence Klopfstein Jun 30 '17 at 18:52
  • 1
    another workaround with npm is in `postinstall` you remove that web.config file, so you don't need to touch global web.config – harishr Jul 01 '17 at 04:51
  • @tiona can you post an answer with an example? If you do it in 3 days I can award you the bounty, but this sounds exactly what I was looking for. – Clarence Klopfstein Jul 01 '17 at 15:10

2 Answers2

7

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

harishr
  • 17,807
  • 9
  • 78
  • 125
4

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.