ESLint: PayloadAction not found in '#reduxjs/toolkit'(import/named) - react-redux

I'm currently building a React app with Redux-toolkit on TypeScript, which was created using create-react-app & I'm getting this error in every Reducer file in my project:
ESLint: PayloadAction not found in '#reduxjs/toolkit'(import/named)
Here is one described for example
Code:
import {createSlice, PayloadAction} from "#reduxjs/toolkit" // An error is coming from here
export interface IInitialState {
isDisSignUp: boolean
}
const initialState: IInitialState = {
isDisSignUp: true,
}
export const buttonSlice = createSlice({
name: "button",
initialState,
reducers: {
disSignUpButton(state, action: PayloadAction<boolean>) {
state.isDisSignUp = action.payload
},
},
})
export default buttonSlice.reducer
My .eslintrc.json
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:#typescript-eslint/recommended",
"plugin:import/recommended",
"prettier"
],
"parser": "#typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true,
"modules": true
},
"ecmaVersion": "latest",
"sourceType": "module",
"project": "tsconfig.json"
},
"plugins": ["react", "#typescript-eslint", "react-hooks", "import"],
"rules": {
"indent": [
"error",
4,
{
"SwitchCase": 1
}
],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "double"],
"semi": ["error", "never"],
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"react/jsx-filename-extension": [
1,
{
"extensions": [".tsx"]
}
],
"import/prefer-default-export": "off",
"import/extensions": [
"error",
"ignorePackages",
{
"ts": "never",
"tsx": "never"
}
]
},
"settings": {
"import/resolver": {
"node": {
"extensions": [".jsx", ".js", ".ts", ".tsx"]
},
"typescript": {
"alwaysTryTypes": true
}
}
}
}
My .tsconfig.json
{
"compilerOptions": {
"target": "ES6",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": ["src"]
}
My package.json
{
"name": "test_task__myself2",
"version": "0.1.0",
"private": true,
"dependencies": {
"#reduxjs/toolkit": "^1.8.3",
"#testing-library/jest-dom": "^5.14.1",
"#testing-library/react": "^13.0.0",
"#testing-library/user-event": "^13.2.1",
"#types/jest": "^27.0.1",
"#types/node": "^16.7.13",
"#types/react": "^18.0.0",
"#types/react-dom": "^18.0.0",
"#types/react-redux": "^7.1.24",
"#types/react-router-dom": "^5.3.3",
"#typescript-eslint/eslint-plugin": "^5.30.7",
"#typescript-eslint/parser": "^5.30.7",
"axios": "^0.27.2",
"classnames": "^2.3.1",
"dotenv": "^16.0.1",
"email-validator": "^2.0.4",
"eslint-plugin-react": "^7.20.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-redux": "^8.0.2",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.1",
"redux": "^4.2.0",
"sass": "^1.54.0",
"typescript": "^4.4.2",
"web-vitals": "^2.1.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"eslint": "^7.2.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-typescript": "^2.7.1",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsx-a11y": "^6.3.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react-hooks": "^4",
"node-sass": "^7.0.1",
"prettier": "^2.6.2"
}
}
Edit
This solution helped me:
Edit .eslintrc.json
"settings": {
"import/parsers": {
"#typescript-eslint/parser": [".ts", ".tsx"]
},
"import/resolver": {
"typescript": {
"alwaysTryTypes": true
}
}
}

Try :
import type {PayloadAction} from "#reduxjs/toolkit"

Try using this, it worked for me
import {createSlice, PayloadAction} from "toolkit"
If this doesn't work, try editing some parts of file to this:
"settings": {
"import/parsers": {
"#typescript-eslint/parser": [".ts", ".tsx"]
},
"import/resolver": {
"typescript": {
"alwaysTryTypes": true
}
}
}

Related

Webpack module federation error: Cannot destructure property `ModuleFederationPlugin` of 'undefined' or 'null'

I am currently modifying the configuration file a Vue app (acting here as a host app) to implement the plugin of webpack : ModuleFederationPlugin.
The goal for me is to set up a micro-frontend architecture by getting a component from a remote app called "foo".
Here is the code to reproduce the issue :
config file host app :
const path = require("path");
const helpers = require("./config/helpers");
const { ModuleFederationPlugin } = require("webpack").container;
const config = {
configureWebpack: {
entry: {
polyfill: "#babel/polyfill",
},
stats: {
cached: false,
cachedAssets: false,
chunks: false,
chunkModules: false,
chunkOrigins: false,
modules: false,
},
devServer: {
historyApiFallback: true,
port: 8765,
},
plugins: [
new ModuleFederationPlugin({
name: "vue",
remotes: {
foo: "foo#http://localhost:5173/remoteEntry.js",
},
}),
],
},
pluginOptions: {
"style-resources-loader": {
preProcessor: "scss",
patterns: [],
},
},
};
module.exports = config;
package.json host app :
{
"name": "Test",
"version": "1.0.0",
"description": "Test",
"author": "Test",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build"
},
"dependencies": {
"vue": "^2.6.10"
},
"devDependencies": {
"#babel/core": "7.7.2",
"#babel/plugin-transform-runtime": "7.6.2",
"#babel/preset-env": "7.7.1",
"#babel/register": "7.7.0",
"#vue/cli-plugin-babel": "^4.0.5",
"#vue/cli-plugin-eslint": "^4.0.5",
"#vue/cli-service": "^4.0.5",
"#vue/eslint-config-airbnb": "^5.0.0",
"babel-plugin-istanbul": "5.2.0",
"cache-loader": "^4.1.0",
"eventsource-polyfill": "0.9.6",
"image-webpack-loader": "^6.0.0",
"karma-webpack": "4.0.2",
"selenium-server": "3.141.59",
"url-loader": "^2.2.0",
"vue-cli-plugin-style-resources-loader": "^0.1.4",
"vue-loader": "15.7.2",
"vue-style-loader": "4.1.2",
"vue-template-compiler": "2.6.10",
"webpack": "^4.41.2",
"webpack-merge": "4.2.2"
},
"engines": {
"node": ">= 8.0.0",
"npm": ">= 5.0.0"
}
}
yarn version host app : 1.22.19
node version host app : v12.0.0
config file remote app :
import svgr from "vite-plugin-svgr"
import { defineConfig } from "vite"
import react from "#vitejs/plugin-react"
import * as path from "path"
import federation from "#originjs/vite-plugin-federation"
export default defineConfig({
plugins: [
svgr(),
react(),
federation({
name: "foo",
filename: "remoteEntry.js",
exposes: {
"./App": "./src/App.tsx",
},
}),
],
build: {
target: "esnext",
assetsDir: "assets",
},
server: {
host: "0.0.0.0",
port: 5173,
},
})
package.json file of the remote app :
{
"name": "test",
"version": "1.0.0",
"description": "test",
"author": "test",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"build:prod": "tsc && vite build",
"build:demo": "tsc && vite build --mode demo",
"preview": "vite preview",
"lint:check": "eslint \"./src/**/*.{ts,tsx}\"",
"lint:fix": "eslint --fix \"./src/**/*.{ts,tsx}\"",
"prettier:check": "prettier --check .",
"prettier:fix": "prettier --write ."
},
"dependencies": {
"#emotion/react": "^11.10.0",
"#emotion/styled": "^11.10.0",
"#mui/icons-material": "^5.10.9",
"#mui/material": "^5.10.0",
"#mui/x-date-pickers": "^5.0.0",
"#originjs/vite-plugin-federation": "^1.1.11",
"axios": "^0.27.2",
"classnames": "^2.3.1",
"dayjs": "^1.11.5",
"i18next": "^21.8.14",
"moment": "^2.29.4",
"npm": "^8.19.2",
"react": "^18.2.0",
"react-charts": "=3.0.0-beta.30",
"react-confetti": "^6.1.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.33.1",
"react-i18next": "^11.18.1",
"react-number-format": "^5.0.1",
"react-router-dom": "^6.3.0"
},
"devDependencies": {
"#types/node": "^18.7.18",
"#types/react": "^18.0.15",
"#types/react-dom": "^18.0.6",
"#typescript-eslint/eslint-plugin": "^5.30.7",
"#typescript-eslint/parser": "^5.30.7",
"#vitejs/plugin-react": "^2.0.0",
"eslint": "^8.20.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-react": "^7.30.1",
"prettier": "^2.7.1",
"sass": "^1.55.0",
"typescript": "^4.6.4",
"vite": "^3.0.0",
"vite-plugin-svgr": "^2.2.1"
}
}
yarn version of the remote app : 1.22.19
node version of the remote app : v12.0.0
Here is what I get when running the host app with "yarn serve" :
error logs when launching the app
My goal is then to be able to use the component App from the remote app in the host app by importing it like that :
Vue.component("App", () => import("foo/App"));

Receiving "Error: Can't walk dependency graph: ENOENT: no such file or directory" when run the test

I am trying to apply cucumber BDD with my cypress. But getting below error.
Error: Can't walk dependency graph: ENOENT: no such file or directory, lstat 'C:\Users\admin\LegrandRX_Cucumber\process'
required by C:\Users\admin\LegrandRX_Cucumber\node_modules\cypress-cucumber-preprocessor\lib\getStepDefinitionsPaths.js
Here is my cypress.json file
{
"reporter": "cypress-mochawesome-reporter",
"reporterOptions": {
"reportDir": "cypress/Reports",
"charts": true,
"overwrite": false,
"html": false,
"json": true,
"reportPageTitle": "Legrande Cypress",
"reportFilename": "Legrande Cypress Test Report",
"embeddedScreenshots": true,
"inlineAssets": true
},
"defaultCommandTimeout": 30000,
"retries": {
"runMode": 1,
"openMode": 1
},
"video": false,
"scrollBehavior": "nearest",
"testFiles": "**/*.{feature,features}",
"chromeWebSecurity": false,
}
And Here is my package.json file
{
"name": "cypressautomation",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"delete:reportFolder": "rm -rf mochawesome-report/",
"test:cli": "npm run delete:reportFolder && cypress run",
"merge:reports": "mochawesome-merge mochawesome-report/*.json > cypress-combined-report.json",
"create:html:report": "npm run merge:reports && marge --reportDir TestReport cypress-combined-report.json",
"cy:run": "cypress run",
"record-test": "cypress run --record --key 18415255-c402-40f0-b983-ab9c3bdf3dc4"
},
"cypress-cucumber-preprocessor": {
"nonGlobalStepDefinitions": true
},
"reporter": "cypress-mochawesome-reporter",
"reporterOptions": {
"reportDir": "cypress/Reports",
"charts": true,
"reportPageTitle": "My Test Suite",
"embeddedScreenshots": true,
"inlineAssets": true
},
"video": false,
"author": "weblylab",
"license": "ISC",
"devDependencies": {
"cypress": "^9.5.0",
"cypress-cucumber-preprocessor": "^4.3.1",
"cypress-file-upload": "^5.0.2",
"cypress-mochawesome-reporter": "^2.2.0",
"cypress-slack-reporter": "^1.2.1",
"cypress-xpath": "^1.6.1",
"faker": "^5.5.3",
"i": "^0.3.6",
"mocha": "^8.4.0",
"mochawesome": "^6.2.2",
"mochawesome-merge": "^4.2.0",
"mochawesome-report-generator": "^5.2.0",
"tsconfig-paths": "^3.9.0"
},
"dependencies": {
"#auth0/auth0-spa-js": "^1.13.6",
"#types/bluebird": "^3.5.33",
"#types/lodash": "^4.14.168",
"chai": "^4.3.0",
"cypress-iframe": "^1.0.1",
"cypress-skip-test": "^1.0.0",
"delay": "^5.0.0",
"Faker": "^0.7.2",
"lodash": "^4.17.21",
"moment": "^2.29.1",
"resolve-url": "^0.2.1",
"save": "^2.4.0",
"source-map-resolve": "^0.6.0",
"urix": "^0.1.0",
"xlsx": "^0.17.0"
}
}
My folder structure, .js file and .feature file
And in my index.js file
const cucumber = require('cypress-cucumber-preprocessor').default
module.exports = (on, config) => {
on('file:preprocessor', cucumber())
}
Any idea what's wrong here?

Webpack 5 + Angular 11 Error: ./node_modules/msnodesqlv8/build/Release/sqlserverv8.node 1:2

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

Firefox 60.9 Not Loading es2015 modules (Angular 8)

I have an Angular 8 application using differential loading. The production build configuration creates ES5 and ES2015 modules for differential loading. Chrome, Edge, IE11 and latest FireFox all load correctly in Windows 10.
Unfortunately, the version of FF installed in the Production Environment is 60.9 and this version has issues with the modules.
package.json
"name": "rmt-v2",
"version": "3.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"build:docker": "ng b -c=docker --watch",
"build:prod": "ng b -c=prod",
"build:dev": "ng s -c=dev --watch"
},
"private": true,
"dependencies": {
"#ag-grid-community/all-modules": "^22.1.1",
"#angular/animations": "~8.2.14",
"#angular/cdk": "^8.2.3",
"#angular/common": "~8.2.14",
"#angular/compiler": "~8.2.14",
"#angular/core": "~8.2.14",
"#angular/forms": "~8.2.14",
"#angular/platform-browser": "~8.2.14",
"#angular/platform-browser-dynamic": "~8.2.14",
"#angular/router": "~8.2.14",
"#fortawesome/angular-fontawesome": "^0.5.0",
"#fortawesome/fontawesome-svg-core": "^1.2.26",
"#fortawesome/free-regular-svg-icons": "^5.12.0",
"#fortawesome/free-solid-svg-icons": "^5.12.0",
"#ng-bootstrap/ng-bootstrap": "^5.2.1",
"#types/heatmap.js": "^2.0.36",
"#types/leaflet": "^1.5.12",
"#types/leaflet-draw": "^1.0.3",
"ag-grid-angular": "^22.1.1",
"ag-grid-community": "^22.1.1",
"angular-bootstrap-datetimepicker": "^4.0.2",
"angular-mocks": "^1.7.9",
"angular-split": "^3.0.2",
"angular-webstorage-service": "^1.0.2",
"bootstrap": "^4.4.1",
"classlist.js": "^1.1.20150312",
"core-js": "^3.6.4",
"file-saver": "^2.0.2",
"highcharts": "^8.1.2",
"highcharts-angular": "^2.4.0",
"highcharts-custom-events": "^3.0.4",
"leaflet": "^1.6.0",
"leaflet-draw": "^1.0.4",
"leaflet-heatmap": "^1.0.0",
"moment-range": "^4.0.2",
"ng2-dragula": "^2.1.1",
"ngx-contextmenu": "^5.1.0",
"ngx-device-detector": "^1.4.6",
"ngx-markdown": "^9.0.0",
"open-iconic": "^1.1.1",
"rxjs": "~6.4.0",
"sanitize-html": "^1.27.2",
"tslib": "^1.13.0",
"web-animations-js": "^2.3.2",
"zone.js": "~0.9.1"
},
"devDependencies": {
"#angular-devkit/build-angular": "~0.803.26",
"#angular/cli": "~8.3.26",
"#angular/compiler-cli": "~8.2.14",
"#angular/language-service": "~8.2.14",
"#types/core-js": "^2.5.2",
"#types/file-saver": "^2.0.1",
"#types/jasmine": "~3.3.8",
"#types/jasminewd2": "~2.0.3",
"#types/node": "~8.9.4",
"angular-router-loader": "^0.8.5",
"angular2-template-loader": "^0.6.2",
"angular2-toaster": "^8.0.0",
"autoprefixer": "^9.7.4",
"awesome-typescript-loader": "^5.2.1",
"babel-loader": "^8.0.6",
"clean-webpack-plugin": "^3.0.0",
"codelyzer": "^5.0.0",
"cross-loader": "^0.1.0",
"css-loader": "^3.4.2",
"ejs-loader": "^0.3.5",
"exports-loader": "^0.7.0",
"file-loader": "^5.0.2",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^3.2.0",
"istanbul-instrumenter-loader": "^3.0.1",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.1.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"mini-css-extract-plugin": "^0.9.0",
"moment": "^2.24.0",
"node-sass": "^4.14.1",
"postcss-loader": "^3.0.0",
"precss": "^4.0.0",
"protractor": "~5.4.0",
"pub": "^0.2.0",
"pug": "^2.0.4",
"pug-loader": "^2.4.0",
"raw-loader": "^4.0.0",
"source-map-loader": "^0.2.4",
"to-string-loader": "^1.1.6",
"ts-node": "~7.0.0",
"tslint": "~5.15.0",
"typescript": "~3.5.3",
"webpack": "^4.41.5",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.11.0",
"webpack-merge": "^4.2.2"
}
}
Angular.json
{
"$schema": "./node_modules/#angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"rmt-v2": {
"projectType": "application",
"schematics": {
"#schematics/angular:component": {
"style": "scss"
}
},
"root": "",
"sourceRoot": "src",
"prefix": "",
"architect": {
"build": {
"builder": "#angular-devkit/build-angular:browser",
"options": {
"showCircularDependencies": true,
"outputPath": "dist",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": false,
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"./node_modules/leaflet/dist/leaflet.css",
"./node_modules/leaflet-draw/dist/leaflet.draw.css",
"./node_modules/bootstrap/scss/bootstrap.scss",
"src/styles/styles.scss",
"src/styles/_reset.css",
"src/styles/bootstrapCustom.css"
],
"scripts": [
"./node_modules/marked/lib/marked.js",
"./node_modules/leaflet/dist/leaflet.js",
"./node_modules/heatmap.js/build/heatmap.min.js",
"./node_modules/leaflet-heatmap/leaflet-heatmap.js",
"./node_modules/leaflet-draw/dist/leaflet.draw.js",
"./node_modules/sanitize-html/dist/sanitize-html.min.js"
]
},
"configurations": {
"prod": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "7mb",
"maximumError": "10mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
]
},
"docker": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.docker.ts"
}
],
"optimization": false,
"outputHashing": "all",
"sourceMap": true,
"extractCss": true,
"namedChunks": false,
"aot": false,
"extractLicenses": true,
"vendorChunk": true,
"buildOptimizer": false,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
]
},
"dev": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.dev.ts"
}
],
"optimization": false,
"outputHashing": "all",
"sourceMap": true,
"extractCss": true,
"namedChunks": false,
"aot": false,
"extractLicenses": true,
"vendorChunk": true,
"buildOptimizer": false,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
]
}
}
},
"serve": {
"builder": "#angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "rmt-v2:build"
},
"configurations": {
"production": {
"browserTarget": "rmt-v2:build:production"
},
"docker": {
"browserTarget": "rmt-v2:build:docker"
},
"dev": {
"browserTarget": "rmt-v2:build:dev"
}
}
},
"extract-i18n": {
"builder": "#angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "rmt-v2: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": [
"./node_modules/bootstrap/dist/css/bootstrap.css",
"src/styles/styles.scss",
"src/styles/_reset.css",
"src/styles/bootstrapCustom.css"
],
"scripts": []
}
},
"lint": {
"builder": "#angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.app.json",
"tsconfig.spec.json",
"e2e/tsconfig.json"
],
"exclude": [
"**/node_modules/**"
]
}
},
"e2e": {
"builder": "#angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "rmt-v2:serve"
},
"configurations": {
"production": {
"devServerTarget": "rmt-v2:serve:production"
}
}
}
}
}},
"defaultProject": "rmt-v2"
}
tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./src",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"paths": {
"#config/*": [ "../config/*" ],
"#app/*": ["app/*"]
},
"allowSyntheticDefaultImports": true,
"typeRoots": [
"node_modules/#types"
],
"lib": [
"es2018",
"dom"
],
"resolveJsonModule": true,
"esModuleInterop": true,
"skipLibCheck": true
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
}
}
The Network Tab in the Dev tools shows the following
Generated Script Tags in index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My Angular 8 App</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="styles.94bcefb507c368697735.css">
<link rel="stylesheet" href="main.954525c3d786f7058e13.css">
</head>
<body>
<app-root></app-root>
<script src="runtime-es2015.242f71ace90ec041b135.js" type="module"></script>
<script src="runtime-es5.242f71ace90ec041b135.js" nomodule defer></script>
<script src="polyfills-es5.4d6e5b779dfe03b63b7e.js" nomodule defer></script>
<script src="polyfills-es2015.7639006645731a3f7d9f.js" type="module"></script>
<script src="scripts.399fa4e8eb4db92676bf.js" defer></script>
<script src="main-es2015.692bc22eac2b55aeea5e.js" type="module"></script>
<script src="main-es5.692bc22eac2b55aeea5e.js" nomodule defer></script>
</body>
</html>
I can target ES5 modules only, but then IE11 breaks and I'd really prefer to maintain differential loading. I have no control over the version of FF installed in the Production Environment.
Thanks in advance!
Firefox 60.0 to 63.0.3 (<64.0) support type="module", however it is not until firefox 64.0 that passing credentials when retrieving scripts of type module is supported.
Thus the reason your ssl fails is because firefox isn't passing the cert/credentials.
Haven't created a way to get the auto-generated script tags to handle this for me yet, however, did find out in ff -> about:config, search for 'moduleScript', turn from 'true' to 'false' such that firefox 60->63.0.3 will grab the es5 version (using credentials).

`SCSS` doesn't work after Updating from Angular 9 to Angular 10

I updated my Angular application from version 9 to 10. Before updating it was working correctly. Now it's getting this error:
ERROR in ./src/assets/scss/argon.scss (./node_modules/css-loader/dist/cjs.js??ref--13-1!./node_modules/postcss-loader/src??embedded!./node_modules/resolve-url-loader??ref--13-3!./node_modules/#angular-devkit/build-angular/node_modules/sass-loader/dist/cjs.js??ref--13-4!./src/assets/scss/argon.scss)
Module build failed (from ./node_modules/#angular-devkit/build-angular/node_modules/sass-loader/dist/cjs.js):
SassError: File to import not found or unreadable: custom/alert.
on line 5 of src/assets/scss/custom/_components.scss
from line 65 of src/assets/scss/argon.scss
>> #import "custom/alert";
I tried so many answers in StackOverflow and GitHub which it would not help me.
I attached my Angular.JSON and Package.JSON:
angular.json:
{
"$schema": "./node_modules/#angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"argon-dashboard-angular": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"schematics": {
"#schematics/angular:component": {
"styleext": "scss"
}
},
"architect": {
"build": {
"builder": "#angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": ["src/favicon.ico", "src/assets"],
"styles": [
"src/styles.scss",
"src/assets/scss/argon.scss",
"node_modules/sweetalert2/src/sweetalert2.scss"
],
"scripts": [
"node_modules/chart.js/dist/Chart.min.js",
"node_modules/clipboard/dist/clipboard.min.js",
"node_modules/sweetalert2/dist/sweetalert2.js"
]
},
"configurations": {
"production": {
"fileReplacements": [{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true
}
}
},
"serve": {
"builder": "#angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "argon-dashboard-angular:build"
},
"configurations": {
"production": {
"browserTarget": "argon-dashboard-angular:build:production"
}
}
},
"extract-i18n": {
"builder": "#angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "argon-dashboard-angular:build"
}
},
"test": {
"builder": "#angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "src/karma.conf.js",
"styles": ["src/styles.css"],
"scripts": [],
"assets": ["src/favicon.ico", "src/assets"]
}
},
"lint": {
"builder": "#angular-devkit/build-angular:tslint",
"options": {
"tsConfig": ["src/tsconfig.app.json", "src/tsconfig.spec.json"],
"exclude": ["**/node_modules/**"]
}
}
}
},
"argon-dashboard-angular-e2e": {
"root": "e2e/",
"projectType": "application",
"architect": {
"e2e": {
"builder": "#angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "argon-dashboard-angular:serve"
},
"configurations": {
"production": {
"devServerTarget": "argon-dashboard-angular:serve:production"
}
}
},
"lint": {
"builder": "#angular-devkit/build-angular:tslint",
"options": {
"tsConfig": "e2e/tsconfig.e2e.json",
"exclude": ["**/node_modules/**"]
}
}
}
}
},
"defaultProject": "argon-dashboard-angular",
"schematics": {
"#schematics/angular:component": {
"styleext": "scss"
}
},
"cli": {
"analytics": false
}
}
package.json:
{
"name": "argon-dashboard-angular",
"version": "1.1.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"install:clean": "rm -rf node_modules/ && rm -rf package-lock.json && npm install && npm start"
},
"private": true,
"dependencies": {
"#angular/animations": "10.1.1",
"#angular/common": "10.1.1",
"#angular/compiler": "10.1.1",
"#angular/core": "10.1.1",
"#angular/fire": "^6.0.2",
"#angular/forms": "10.1.1",
"#angular/http": "^7.2.16",
"#angular/localize": "^9.0.5",
"#angular/platform-browser": "10.1.1",
"#angular/platform-browser-dynamic": "10.1.1",
"#angular/router": "10.1.1",
"#ckeditor/ckeditor5-angular": "^1.2.3",
"#ckeditor/ckeditor5-build-classic": "^21.0.0",
"#ng-bootstrap/ng-bootstrap": "^6.0.0",
"#sweetalert2/ngx-sweetalert2": "^8.1.1",
"angular-file-uploader": "^7.0.1",
"bootstrap": "^4.5.2",
"chart.js": "2.7.3",
"clipboard": "2.0.4",
"core-js": "3.6.4",
"firebase": "^7.19.1",
"ngx-clipboard": "13.0.0",
"ngx-quill": "^12.0.1",
"ngx-toastr": "12.0.0",
"nouislider": "13.1.1",
"quill": "^1.3.7",
"rxjs": "^7.0.0-beta.5",
"sass-loader": "^10.0.2",
"sweetalert2": "^10.0.2",
"tslib": "2.0.1",
"zone.js": "0.11.1"
},
"devDependencies": {
"#angular-devkit/build-angular": "0.1001.1",
"#angular/cli": "^10.1.1",
"#angular/compiler-cli": "^10.1.1",
"#angular/language-service": "^10.1.1",
"#types/jasmine": "^3.5.8",
"#types/jasminewd2": "^2.0.8",
"#types/node": "^13.7.7",
"codelyzer": "^5.2.1",
"jasmine-core": "^3.5.0",
"jasmine-spec-reporter": "^4.2.1",
"karma": "^4.4.1",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage-istanbul-reporter": "^2.1.1",
"karma-jasmine": "^3.1.1",
"karma-jasmine-html-reporter": "^1.5.2",
"node-sass": "^4.14.1",
"protractor": "7.0.0",
"ts-node": "9.0.0",
"tslint": "6.1.3",
"typescript": "4.0.2"
}
}
I fixed this. I updated all my SCSS files path by manually and build it again. previously as an example there was the path like this which is completely working with a fine in angular 9.
angular 9 import
#import "custom/components";
when I using angular 10 I updated all my SCCS path to like this
#import "./custom/components";
after above-mentioned changes appear project built successfully.

Resources