I wanted to create a small, hello world, single application page web site and I keep having errors. I searched for the error, implemented the proposed changes and other issues happenend.
Could you please help me understand the issue, I don’t want server components, only typescript and html running on NodeJs as I understood Application Insights won’t work without NodeJs working with VSCode on Windows 10.
App.ts
import * as appInsights from '../node_modules/applicationinsights/out/applicationinsights.js';
function main(_t: number): void {
appInsights.setup('***').start();
}
main(1);
package.json
{
"main": "./js/app.js",
"type": "module",
"scripts": {
"start": "set DEBUG_MODE=true && start python -m http.server 1973 && start http://localhost:1973"
},
"devDependencies": {
"@types/node": "^20.8.10",
"typescript": "^5.2.2"
},
"dependencies": {
"applicationinsights": "^2.9.5"
}
}
tsConfig.json
{
"compilerOptions": {
"target": "ES6",
"module": "ES2015",
"outDir": "./js",
"rootDir": "./ts",
"moduleResolution": "Bundler",
"baseUrl": "./",
"paths": {
"*": ["node_modules/*"]
}
},
"include": ["./ts/**/*.ts", "@types/**/*.d.ts"]
}
I used '../node_modules/applicationinsights/out/applicationinsights.js' as I had the message: Uncaught TypeError: Failed to resolve module specifier "applicationinsights". Relative references must start with either "/", "./", or "../".
If you can provide any help, thanks.
only typescript and html on NodeJs as I understood Application Insights won’t work without NodeJs in this configuration, working with VSCode on Windows 10.
I wanted to create a small, hello world
Please follow the below steps.
npm init -y
[email protected]
.npx tsc --init
app.ts
file in the project directory and the below code.import * as appInsights from 'applicationinsights';
// Set up Application Insights
appInsights.setup('InstrumentationKey').start();
// Example: Track a custom event
const client = appInsights.defaultClient;
client.trackEvent({ name: 'MyCustomEvent', properties: { key: 'value' } });
console.log('Message logged to Application Insights.');
npx tsc
Executed:
Result:
Package.json:
{
"name": "rxjsclient",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@microsoft/applicationinsights-web": "^3.1.2",
"applicationinsights": "^3.0.0-beta.12",
"typescript": "^5.4.4"
},
"devDependencies": {
"@types/node": "^20.12.5"
}
}