1

In package.json I have:

{
  "name": "projName",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "prestart": "node aspnetcore-https",
...

when I run npm start I get:

Error: Cannot find module '...\aspnetcore-https'

How can I install the module? If I try

npm install  aspnetcore-https

I get:

npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/aspnetcore-https - Not found

I have this line I think because I copied the packages.json from a Visual Studio Angular Typescript project into a Typescript only source code folder, but the latter folder project should still work if I install the correct package?

Update: the project runs correctly from npm start if I just remove the line

"prestart": "node aspnetcore-https",

but I'd like to understand why I can't install this module?

2
  • I don't think it's an npm package. But some sort of js file that doesn't exist in your template it seems Commented Sep 30, 2022 at 8:56
  • 3
    You can't install aspnetcore-https package since it's not in npm registry. Commented Sep 30, 2022 at 8:57

2 Answers 2

4

Visual studio installs a aspnetcore-https.js file into the ClientApp folder. This file is typically excluded from source control. The file is missing from your project folder.

Below is the contents of my copy:

// This script sets up HTTPS for the application using the ASP.NET Core HTTPS certificate
const fs = require('fs');
const spawn = require('child_process').spawn;
const path = require('path');

const baseFolder =
  process.env.APPDATA !== undefined && process.env.APPDATA !== ''
    ? `${process.env.APPDATA}/ASP.NET/https`
    : `${process.env.HOME}/.aspnet/https`;

const certificateArg = process.argv.map(arg => arg.match(/--name=(?<value>.+)/i)).filter(Boolean)[0];
const certificateName = certificateArg ? certificateArg.groups.value : process.env.npm_package_name;

if (!certificateName) {
  console.error('Invalid certificate name. Run this script in the context of an npm/yarn script or pass --name=<<app>> explicitly.')
  process.exit(-1);
}

const certFilePath = path.join(baseFolder, `${certificateName}.pem`);
const keyFilePath = path.join(baseFolder, `${certificateName}.key`);

if (!fs.existsSync(certFilePath) || !fs.existsSync(keyFilePath)) {
  spawn('dotnet', [
    'dev-certs',
    'https',
    '--export-path',
    certFilePath,
    '--format',
    'Pem',
    '--no-password',
  ], { stdio: 'inherit', })
  .on('exit', (code) => process.exit(code));
}
Sign up to request clarification or add additional context in comments.

1 Comment

Note that if you create a new Angular/whatever front end app in VS it will create this file for you which can copy across to your project. I mention this in case this code changes in future
2

If you took this package file from a Visual Studio app, it probably means that they used a custom project generator (not @angular/cli) and they added a custom file called aspnetcore-https.js.

If you move the package file away from its original folder, it becomes unable to find this file.

This is your issue.

2 Comments

Our experience was that aspnetcore-https.js could not be loaded beccause line 8 could not find the folder ? ${process.env.APPDATA}/ASP.NET/https . For us seemed to be a difference between Visual Studio Pro and Enterprise this Folder had been created for Visual Studio Enterprise but not for Pro when Visual Studio Prompts to create the Https Certificate. Also it could not save the self signed https certificate which Visual Studio Pro and Enterprise both prompt for to this location: C:\Users\JoeSmith\AppData\Roaming\ASP.NET\https.
For Visual Studio Pro potentially some pathing is incorrect or the user must not have access but we were running it as Administrator. Hopefully this helps the next person the other error you will see is certificate cant be found.

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.