I'm using Webpack 5 and Angular 11
when I execute the command
ng build --prod && ng run test-app:server:production
In the console it gives me an error message:
Error: ./node_modules/msnodesqlv8/build/Release/sqlserverv8.node 1:2
Module parse failed: Unexpected character '�' (1:2)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
and directory is not being built: dist/test-app/server/main.js it only creates itself: dist/test-app/browser/
I don't know where I have badly configured files.
Please help. I don't know what I'm doing wrong.
package.json:
{
"name": "test-app",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"dev:ssr": "ng run test-app:serve-ssr",
"serve:ssr": "node dist/test-app/server/main.js",
"build:ssr": "ng build --prod && ng run test-app:server:production",
"prerender": "ng run test-app:prerender",
"start-webpack:server": "webpack --config webpack.server.config.js "
},
"private": true,
"resolution": {
"webpack": "^5.0.0"
},
"dependencies": {
"#angular/animations": "~11.0.5",
"#angular/common": "~11.0.5",
"#angular/compiler": "~11.0.5",
"#angular/core": "~11.0.5",
"#angular/forms": "~11.0.5",
"#angular/platform-browser": "~11.0.5",
"#angular/platform-browser-dynamic": "~11.0.5",
"#angular/platform-server": "^11.0.7",
"#angular/router": "~11.0.5",
"#nguniversal/express-engine": "^11.0.1",
"express": "^4.17.1",
"msnodesqlv8": "^2.0.8",
"mssql": "^6.3.1",
"rxjs": "~6.6.0",
"tslib": "^2.0.0",
"zone.js": "~0.10.2"
},
"devDependencies": {
"#angular-devkit/build-angular": "~0.1100.5",
"#angular/cli": "~11.0.5",
"#angular/compiler-cli": "~11.0.5",
"#nguniversal/builders": "^11.0.1",
"#types/express": "^4.17.9",
"#types/jasmine": "~3.6.0",
"#types/node": "^12.11.1",
"codelyzer": "^6.0.0",
"jasmine-core": "~3.6.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~5.1.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0",
"protractor": "~7.0.0",
"ts-loader": "^8.0.14",
"ts-node": "^8.3.0",
"tslint": "~6.1.0",
"typescript": "~4.0.2",
"webpack-cli": "^4.3.1"
},
"description": "This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 11.0.5.",
"main": "karma.conf.js",
"keywords": [],
"author": "",
"license": "ISC"
}
angular.json:
{
"$schema": "./node_modules/#angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"test-app": {
"projectType": "application",
"schematics": {
"#schematics/angular:component": {
"style": "scss"
},
"#schematics/angular:application": {
"strict": true
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "#angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/test-app/browser",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": true,
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
]
}
}
},
"serve": {
"builder": "#angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "test-app:build"
},
"configurations": {
"production": {
"browserTarget": "test-app:build:production"
}
}
},
"extract-i18n": {
"builder": "#angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "test-app:build"
}
},
"test": {
"builder": "#angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"scripts": []
}
},
"lint": {
"builder": "#angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.app.json",
"tsconfig.spec.json",
"e2e/tsconfig.json",
"tsconfig.server.json"
],
"exclude": [
"**/node_modules/**"
]
}
},
"e2e": {
"builder": "#angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "test-app:serve"
},
"configurations": {
"production": {
"devServerTarget": "test-app:serve:production"
}
}
},
"server": {
"builder": "#angular-devkit/build-angular:server",
"options": {
"outputPath": "dist/test-app/server",
"main": "server.ts",
"tsConfig": "tsconfig.server.json"
},
"configurations": {
"production": {
"outputHashing": "media",
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"sourceMap": false,
"optimization": true
}
}
},
"serve-ssr": {
"builder": "#nguniversal/builders:ssr-dev-server",
"options": {
"browserTarget": "test-app:build",
"serverTarget": "test-app:server"
},
"configurations": {
"production": {
"browserTarget": "test-app:build:production",
"serverTarget": "test-app:server:production"
}
}
},
"prerender": {
"builder": "#nguniversal/builders:prerender",
"options": {
"browserTarget": "test-app:build:production",
"serverTarget": "test-app:server:production",
"routes": [
"/"
]
},
"configurations": {
"production": {}
}
}
}
}
},
"defaultProject": "test-app",
"cli": {
"analytics": "e9a52f4c-af8d-4030-8d24-ba3f4b17ec39"
}
}
server.ts:
import 'zone.js/dist/zone-node';
import { ngExpressEngine } from '#nguniversal/express-engine';
import * as express from 'express';
import { join } from 'path';
import { AppServerModule } from './src/main.server';
import { APP_BASE_HREF } from '#angular/common';
import { existsSync } from 'fs';
import { TestRoute } from './server/router/test';
const testRoute: TestRoute = new TestRoute();
export function app(): express.Express {
const server = express();
const distFolder = join(process.cwd(), 'dist/test-app/browser');
const indexHtml = existsSync(join(distFolder, 'index.original.html')) ? 'index.original.html' : 'index';
server.engine('html', ngExpressEngine({
bootstrap: AppServerModule,
}));
server.set('view engine', 'html');
server.set('views', distFolder);
server.get('*.*', express.static(distFolder, {
maxAge: '1y'
}));
server.get('*', (req, res) => {
res.render(indexHtml, { req, providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }] });
});
return server;
}
function run(): void {
const port = process.env.PORT || 4000;
const server = app();
server.listen(port, () => {
console.log(`Node Express server listening on http://localhost:${port}`);
});
}
// Webpack will replace 'require' with '__webpack_require__'
// '__non_webpack_require__' is a proxy to Node 'require'
// The below code is to ensure that the server is run only when not requiring the bundle.
declare const __non_webpack_require__: NodeRequire;
const mainModule = __non_webpack_require__.main;
const moduleFilename = mainModule && mainModule.filename || '';
if (moduleFilename === __filename || moduleFilename.includes('iisnode')) {
run();
}
export * from './src/main.server';
commented out on this line of code:
const testRoute: TestRoute = new TestRoute();
and execute the command
ng build --prod && ng run test-app: server: production
does not display errors.
The TestRoute class contains a reference to the library and connecting to the database:
import { Request, Response, NextFunction, response } from 'express';
export class TestRoute {
contractorRoute(app: any): void {
app.route('/api/get-test').get((req: Request, res: Response, next: NextFunction) => {
var sql = require("mssql/msnodesqlv8");
let config = {
server: 'SQLDXXX\\XXX',
database: 'XXX',
driver: "msnodesqlv8",
options: {
trustedConnection: true
}
};
let connect = new sql.ConnectionPool(config);
connect.connect().then(() => {
connect.request().query('select * from [test].[dbo].[test]', (err: TypeError, recordset: any) => {
if (err) {
console.error(" Error: " + err );
return;
} else {
res.send(recordset);
}
connect.close();
})
}).catch((err: any) => {
console.error(" Error: " + err );
});
})
}
}
tsconfig.app.json
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/app",
"types": [
"node"
]
},
"files": [
"src/main.ts",
"src/polyfills.ts"
],
"include": [
"src/**/*.d.ts"
]
}
tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"module": "es2020",
"lib": [
"es2018",
"dom"
]
},
"angularCompilerOptions": {
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}
tsconfig.server.json
{
"extends": "./tsconfig.app.json",
"compilerOptions": {
"outDir": "./out-tsc/app",
"target": "es2020",
"module": "commonjs",
"types": [
"node"
]
},
"files": [
"src/main.server.ts",
"server.ts"
],
"angularCompilerOptions": {
"entryModule": "./src/app/app.server.module#AppServerModule"
}
}
webpack.server.config.js
const path = require("path");
const webpack = require("webpack");
module.exports = {
entry: { server: "./server.ts" },
resolve: { extensions: [".js", ".ts"] },
target: "node",
mode: "none",
// this makes sure we include node_modules and other 3rd party libraries
externals: [/node_modules/],
output: {
path: path.join(__dirname, "dist"),
filename: "[name].js"
},
module: {
rules: [
{ test: /\.ts$/, loader: "ts-loader" },
{ test: /\.node$/, use: "node-loader" },
]
},
plugins: [
// Temporary Fix for issue: https://github.com/angular/angular/issues/11580
// for 'WARNING Critical dependency: the request of a dependency is an expression'
new webpack.ContextReplacementPlugin(
/(.+)?angular(\\|\/)core(.+)?/,
path.join(__dirname, "src"), // location of your src
{} // a map of your routes
),
new webpack.ContextReplacementPlugin(
/(.+)?express(\\|\/)(.+)?/,
path.join(__dirname, "src"),
{}
)
]
};
the documentation https://www.npmjs.com/package/msnodesqlv8 says about adding a line I added it:
{ test: /\.node$/, use: 'node-loader' }
but the error is still there:
Error: ./node_modules/msnodesqlv8/build/Release/sqlserverv8.node 1:2
Module parse failed: Unexpected character '�' (1:2)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
I don't know what else I should improve.
Thank you for your help
the application example is based on:
https://www.ganatan.com/tutorials/server-side-rendering-with-angular-universal
Building the .dmg works and running the .dmg installer works. When I open the installed app, the app's icon appears in the Mac tool bar for a second and then disappears. An error window then appears that says "App quit unexpectedly."
The app installs and functions perfectly on Windows machines with .exe that Electron-builder had built. I am confused as to how the .dmg is not functioning and working the same way. Is my package.json missing something or incorrect?
I have also attempted to build a .pkg, but the same error occurs.
How I build the file:
Run react-scripts build
Run electron-builder
My pacakge.json:
{
"name": "data-entry",
"packageName": "Data Entry App",
"version": "1.0.1",
"license": "MIT",
"description": "An app to quickly enter survey data.",
"private": true,
"author": "xxx",
"homepage": "./",
"main": "src/start.js",
"productName": "Data Entry App",
"nsis": {
"createDesktopShortcut": "always",
"oneClick": false,
"perMachine": false,
"allowToChangeInstallationDirectory": true
},
"repository": {
"type": "git",
"url": "xxx"
},
"build": {
"files": [
"app/**/*",
"node_modules/**/*",
"package.json"
],
"appId": "com.myapp.DataEntry",
"publish": {
"provider": "github",
"repo": "xxx",
"owner": "xxx"
},
"npmRebuild": false,
"directories": {
"buildResources": "assets"
},
"mac": {
"target": "dmg"
},
"win": {
"target": "nsis"
}
},
"dependencies": {
"#material-ui/core": "^4.9.1",
"#material-ui/icons": "^4.5.1",
"#material-ui/lab": "^4.0.0-alpha.41",
"electron-is-dev": "^1.1.0",
"electron-json-storage": "^4.1.8",
"electron-log": "^4.0.6",
"electron-store": "^5.1.0",
"electron-updater": "^4.2.0",
"firebase": "^7.8.1",
"grpc": "^1.23.3",
"http2": "^3.3.7",
"node": "^10.9.0",
"node-pre-gyp": "^0.12.0",
"notistack": "^0.9.7",
"react": "^16.11.0",
"react-csv": "^1.1.2",
"react-dom": "^16.11.0",
"react-scripts": "3.2.0",
"react-with-firebase-auth": "^1.3.0"
},
"scripts": {
"start": "react-scripts start",
"electron": "electron .",
"pack": "electron-builder --dir",
"dist": "electron-builder",
"react-build": "react-scripts build",
"dist-all": "electron-builder"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"electron": "^7.1.8",
"electron-builder": "^20.44.4"
}
}
Trying to migrate my app from 2 to 3 on android.
I downloaded all the new requirements. Tested environment on a newly template created project and works fine.
In my project, I updated the tsconfig.js file and fixed a few error messages.
These are what I'm left with mainly - errors like:
Property 'NSObject' does not exist on type 'Global'
All have to do with Global.
In code I have it like global.NSObject
but "global" seems to be defined in NS 3.0 - in tns-core-modules/modules.d.ts.
but there's no field for NSobject - ergo the error.
Am I supposed to use global.__native.NSObject???
Also, I've got a worker thread and seems like the signature changed.
Getting errors for onmessage and also the signature of postMessage() seems to have changed - no updates in docs.
global.onmessage = function(msg) {}
Help appreciated as always.
My package.json file
{
"description": "NativeScript Application",
"license": "SEE LICENSE IN <your-license-filename>",
"readme": "NativeScript Application",
"repository": "<fill-your-repository-here>",
"nativescript": {
"id": "dev.myapp.test",
"tns-android": {
"version": "3.2.0"
}
},
"dependencies": {
"nativescript-dev-typescript": "^0.3.7",
"tns-core-modules": "^3.2.0"
},
"devDependencies": {
"babel-traverse": "6.19.0",
"babel-types": "6.19.0",
"babylon": "6.14.1",
"lazy": "1.0.11",
"nativescript-dev-typescript": "^0.3.7",
"typescript": "~2.2.1"
}
}
My tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"noEmitHelpers": true,
"noEmitOnError": true,
"lib": [
"es6",
"dom"
],
"baseUrl": ".",
"paths": {
"*": [
"./node_modules/tns-core-modules/*",
"./node_modules/*"
]
}
},
"exclude": [
"node_modules",
"platforms",
"**/*.aot.ts"
]
}
Hi i have built an app using angular-cli and I am trying to debug it using vs code and Debugger for chrome extension. After a while I was able to make it work, well kind of. What happens is that i can set a break-point in my typescript class but it gets placed on a wrong line number like source map is incorrect.
Debug process - open terminal ng serve than go to debug tab and click F5 in vscode
I have the following:
I use LaunchChrome configuration
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "LaunchChrome",
"type": "chrome",
"request": "launch",
"url": "http://localhost:4200",
"sourceMaps": true,
"webRoot": "${workspaceRoot}",
"diagnosticLogging": true,
"userDataDir": "${workspaceRoot}/.vscode/chrome",
"sourceMapPathOverrides": {
"webpack:///C:*": "c:/*"
}
},
{
"name": "AttachChrome",
"type": "chrome",
"request": "attach",
"port": 9222,
"sourceMaps": true,
"webRoot": "${workspaceRoot}",
"diagnosticLogging": true,
"sourceMapPathOverrides": {
"webpack:///*": "/*"
}
}
]
}
angular-cli.json
{
"project": {
"version": "1.0.0-beta.18",
"name": "frontend"
},
"apps": [
{
"root": "src",
"outDir": "./dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"test": "test.ts",
"tsconfig": "tsconfig.json",
"prefix": "app",
"mobile": false,
"styles": [
"styles.css",
"../semantic/dist/packaged/semantic.css"
],
"scripts": [
"../node_modules/jquery/dist/jquery.js",
"../semantic/dist/packaged/semantic.js",
"../node_modules/chart.js/dist/Chart.bundle.js"
],
"environments": {
"source": "environments/environment.ts",
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"addons": [],
"packages": [],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"prefixInterfaces": false,
"inline": {
"style": false,
"template": false
},
"spec": {
"class": false,
"component": true,
"directive": true,
"module": false,
"pipe": true,
"service": true
}
}
}
tsconfig.json
{
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es6", "dom"],
"module": "es6",
"moduleResolution": "node",
"outDir": "../dist",
"sourceMap": true,
"target": "es5",
"typeRoots": [
"../node_modules/#types"
]
}
}
I have updated to angular-cli-beta19-3 and typescript 2.0.6 and cleared cache in chrome now it works.
UPDATE: using angular 2.4.1 now
Whats funny is that it doesnt work with
"sourceMapPathOverrides": {
"webpack:///*": "${webRoot}/*"
}
defined here https://github.com/Microsoft/vscode-chrome-debug
but it works with
"sourceMapPathOverrides": {
"webpack:///C:*": "c:/*"
}
and for linux as #carpinchosaurio said
"webpack:///*": "/*"
UPDATE 2/21/2017:
With new versions of angular and typescript there is no need for source map path overrides anymore.
"#angular/compiler-cli": "2.4.8",
"#angular/cli": "1.0.0-beta.32.3",
"typescript": "2.1.6"
angular version 2.4.8
Working setup:
{
"version": "0.2.0",
"configurations": [
{
"name": "LaunchChrome",
"type": "chrome",
"request": "launch",
"url": "http://localhost:4200",
"sourceMaps": true,
"webRoot": "${workspaceRoot}",
"userDataDir": "${workspaceRoot}/.vscode/chrome"
}
]
}
for anyone still interested this worked for me -
{
"name": "Launch localhost with sourcemaps",
"type": "chrome",
"request": "launch",
"url": "http://localhost:4200",
"sourceMaps": true,
"webRoot": "${workspaceRoot}/src",
"userDataDir": "${workspaceRoot}/.vscode/chrome",
"sourceMapPathOverrides": {
"webpack:///./~/*": "${workspaceRoot}/node_modules/*",
"webpack:///./src/*": "${workspaceRoot}/src/*"
}
// Uncomment this to get diagnostic logs in the console
// "diagnosticLogging": true
}
Just to emphasize more the updated answer: Currently it's not needed to have the sourceMapPathOverrides property in your launch.json. In case you are updating project from an old Angular, just remove the property and debugging will start working.