node_modules breaks build in Visual Studio

2019-05-06 15:05发布

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?

2条回答
干净又极端
2楼-- · 2019-05-06 15:52

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.

查看更多
在下西门庆
3楼-- · 2019-05-06 15:55

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

查看更多
登录 后发表回答