Reputation: 1211
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?
Upvotes: 0
Views: 2894
Reputation: 1286
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));
}
Upvotes: 3
Reputation: 3521
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.
Upvotes: 2