npm start not run react project - node.js

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
- configuration.module has an unknown property 'loaders'. These properties are valid:
object { exprContextCritical?, exprContextRecursive?, exprContextRegExp?, exprContextRequest?, noParse?, rules?, defaultRules?, unknownContextCritical?, unknownContextRecursive?, unknownContextRegExp?, unknownContextRequest?, unsafeCache?, wrappedContextCritical?, wrappedContextRecursive?, wrappedContextRegExp?, strictExportPresence?, strictThisContextOnImports? }
-> Options affecting the normal modules (NormalModuleFactory).
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! newreact#1.0.0 start: webpack
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the newreact#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Designer\AppData\Roaming\npm-cache_logs\2018-05-16T08_09_23_588Z-debug.log

You really need to tell us the version of webpack you are using and post your webpack.config.js file, but I'll try and help. I'm assuming webpack 4.
This bit of the log says there is something wrong with how you have written your webpack.config.js file.
Webpack has been initialized using a configuration object that does not match the API schema.
This line further describes the problem.
configuration.module has an unknown property 'loaders'.
Then it goes on to tell you what properties are valid, and you'll see loaders is not listed. In webpack 4 you need to use 'rules', not 'loaders'.
These properties are valid: object { exprContextCritical?, exprContextRecursive?, exprContextRegExp?, exprContextRequest?, noParse?, rules?, defaultRules?, unknownContextCritical?, unknownContextRecursive?, unknownContextRegExp?, unknownContextRequest?, unsafeCache?, wrappedContextCritical?, wrappedContextRecursive?, wrappedContextRegExp?, strictExportPresence?, strictThisContextOnImports? }
Your modules object should look something like the following, so perhaps take a look at this page and compare the modules object to your own.
module: {
rules: [
{
test: /\.css$/,
use: [
{ loader: 'style-loader' },
{
loader: 'css-loader',
options: {
modules: true
}
}
]
}
]
}
Hope that helps.

Related

issue with nestjs + fastify-http-proxy

I am trying to build a Nestjs api proxy (pass through). I found this package which is very simple to use: fastify-http-proxy.
The problem is I don't know how to use this package within Nestjs.
Does anybody here any experience with this, please?
import { NestFactory } from '#nestjs/core';
import {
FastifyAdapter,
NestFastifyApplication,
} from '#nestjs/platform-fastify';
import { AppModule } from './app.module';
import proxy from 'fastify-http-proxy';
async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter({logger: true})
);
app.register(proxy, {
upstream: 'http://localhost:3000',
prefix: '/api',
http2: false
});
await app.listen(4000);
}
bootstrap();
$ npm run start
> test-api-gateway#0.0.1 start /test-api-gateway
> nest start
node_modules/fastify-http-proxy/index.d.ts:18:29 - error TS2344: Type 'RawServerBase' does not satisfy the constraint 'RouteGenericInterface'.
Type 'Server' has no properties in common with type 'RouteGenericInterface'.
18 request: FastifyRequest<RawServerBase>,
~~~~~~~~~~~~~
node_modules/fastify-http-proxy/index.d.ts:23:29 - error TS2344: Type 'RawServerBase' does not satisfy the constraint 'RouteGenericInterface'.
Type 'Server' has no properties in common with type 'RouteGenericInterface'.
23 request: FastifyRequest<RawServerBase>,
~~~~~~~~~~~~~
Found 2 error(s).
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test-api-gateway#0.0.1 start: `nest start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the test-api-gateway#0.0.1 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
✘-1 ~/test-api-gateway
it works for me if using const proxy = require('fastify-http-proxy') instead import proxy from 'fastify-http-proxy'

Running webpack throws 'Callback was already called' error

I just started learning webpack to manage dependencies in my project. I am trying to use it to build bundles for my typescript and javascript files. For the typescript files, I am using the ts-loader plugin for handling it. For CSS, I am using the mini-css-extract and an optimize-css-assets plugin. When I try to run webpack, I get the following error and I am not able to figure out what might be causing this error.
user#system spl % npm run build
> spl#1.0.0 build /Users/user/Downloads/spl
> webpack --config webpack.config.js
/Users/user/Downloads/spl/node_modules/neo-async/async.js:16
throw new Error('Callback was already called.');
^
Error: Callback was already called.
at throwError (/Users/user/Downloads/spl/node_modules/neo-async/async.js:16:11)
at /Users/user/Downloads/spl/node_modules/neo-async/async.js:2818:7
at processTicksAndRejections (internal/process/task_queues.js:79:11)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! spl#1.0.0 build: `webpack --config webpack.config.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the spl#1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/user/.npm/_logs/2020-05-14T14_23_32_985Z-debug.log
The following is my webpack.config file that I am using to build my dist files.
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCssAssetsPlugin = require("optimize-css-assets-webpack-plugin");
module.exports = {
mode: 'production',
entry: "./static/js/index.js",
output: {
filename: "bundle.[contentHash].js", // File name with hash, based on content
path: path.resolve(__dirname, 'dist')
},
optimization: {
minimizer: [
new OptimizeCssAssetsPlugin(),
new TerserPlugin(),
new HtmlWebpackPlugin({
template: "./static/index.html",
minify: {
removeAttributeQuotes: true,
collapseWhitespace: true,
removeComments: true
}
})
]
},
plugins: [
new MiniCssExtractPlugin({
filename: "[name].[contentHash].css"
}),
new CleanWebpackPlugin(),
],
module: {
rules: [
{
test: /\.html$/,
use: [ "html-loader" ]
},
{
test: /\.[tj]s$/,
use: "ts-loader",
exclude: /(node_modules|tests)/
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader"
]
}
],
},
resolve: {
alias: {
src: path.resolve(__dirname, 'src'),
static: path.resolve(__dirname, 'static'),
},
extensions: [ '.ts', '.js' ]
}
}
I had the same issue and I realized that I was importing CSS file from my index.html file:
<link rel="stylesheet" href="./css/main.css">
although the CSS file should have been imported from entry file (index.js) using import:
import '../css/main.css';
so I deleted the line <link rel="stylesheet" href="./css/main.css"> and solved the problem.
You can see your HTML file and check if there are any assets imported from your HTML file. I hope it helped.
tl;dr: Upgrading webpack to a newer version solved it for me.
I went into node_modules/neo-async/async.js and modified the onlyOnce so that it gives a bit more descriptive stack trace like this:
/**
* #private
* #param {Function} func
*/
function onlyOnce(func) {
const defined = new Error('onlyOnce first used here')
return function(err, res) {
var fn = func;
func = () => {
console.error(defined);
throwError();
};
fn(err, res);
};
}
The stack trace points into webpack’s internal code, which, when I upgraded to the latest version, solves this issue.
I ran into this issue and was able to determine that the cause was circular dependencies in Typescript, not outdated dependencies as suggested by other answers here. This error appeared when I refactored code from import MyClass from "folder/file" into import { MyClass } from "folder".
I only considered this possibility after reading this post about differences in semantics between export default and other types of exports.
I had this issue and it was related to a recent downgrade someone had made to mini-css-extract-plugin. We are using pnpm, so this answer is specific to that. I had to delete the pnpm-lock.yaml file in the module I was trying to run out of spring boot dashboard in VSCode. This file is generated if it is missing, but for us anyway, it was committed to the repo. If that doesn't work for you, you might also consider deleting the npm-cache and .pnpm-store dirs. The locations of those files are configured in the .npmrc file in your user's home directory.
For me, the issue came after upgrading css-loader. Downgrading it back to the original version did the trick for me
diff --git a/package.json b/package.json
index 7151c509..b0eba48b 100644
--- a/package.json
+++ b/package.json
## -111,7 +111,7 ##
"webpack-merge": "^4.1.3"
},
"devDependencies": {
- "css-loader": "^6.5.1",
+ "css-loader": "^1.0.0",

Electron - WinInstaller

I try to create a windows installer for my elctron application but when I run the file I have this error:
spawn mono ENOENT
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! thermowell-design#1.2.0 installer-win: `npm run pack-win && node installers/windows/createinstaller.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the thermowell-design#1.2.0 installer-win script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
This is the createinstaller.js file:
const createWindowsInstaller = require('electron-winstaller').createWindowsInstaller
const path = require('path')
getInstallerConfig()
.then(createWindowsInstaller)
.catch((error) => {
console.error(error.message || error)
process.exit(1)
})
function getInstallerConfig () {
console.log('creating windows installer')
const rootPath = path.join('./')
const outPath = path.join(rootPath, 'release-builds')
return Promise.resolve({
appDirectory: path.join(outPath, 'Thermowell-Design-win32-x64/'),
authors: 'Pippo',
noMsi: true,
outputDirectory: path.join(outPath, 'windows-installer'),
exe: 'thermowell-design.exe',
setupExe: 'thermowell-design-app.exe',
setupIcon: path.join(rootPath, 'assets', 'images', 'icons', 'logo.ico')
})
}
There are the dependencie version:
electron: 5.0.0-beta.2,
electron-packager: 13.0.1,
electron-winstaller: 2.7.0
end the nodejs version is 10.15.1
It's too late to answer but leaving it for somebody if they need it in future. I got the same problem and here are my fixes:
depending upon my project structure I changed rootPath = path.join(__dirname,'../..')
install mono from https://www.mono-project.com/download/stable/#download-lin-ubuntu
install wine from https://tecadmin.net/install-wine-on-ubuntu/
The two installations are for non-windows platform if your building your installer for windows platform
Those were my fixes but here's another link that might be helpful for you.

NPM run build error

When I run npm run build I get an error. I will get a dist folder.
ERROR in Error: Child compilation failed:
Entry module not found: Error: Can't resolve '/Users/jurdekker/Desktop/OnWeb/O nWeb.react/Sisketeers/dist/index.html' in '/Users/jurdekker/Desktop/OnWeb/OnWe b.react/Sisketeers':
Error: Can't resolve '/Users/jurdekker/Desktop/OnWeb/OnWeb.react/Sisketeers/di st/index.html' in '/Users/jurdekker/Desktop/OnWeb/OnWeb.react/Sisketeers'
- compiler.js:76
[Sisketeers]/[html-webpack-plugin]/lib/compiler.js:76:16
- Compiler.js:304 compile
[Sisketeers]/[webpack]/lib/Compiler.js:304:11
- Compiler.js:514 applyPluginsAsync.err
[Sisketeers]/[webpack]/lib/Compiler.js:514:14
- Tapable.js:202 next
[Sisketeers]/[tapable]/lib/Tapable.js:202:11
- CachePlugin.js:78 Compiler.<anonymous>
[Sisketeers]/[webpack]/lib/CachePlugin.js:78:5
- Tapable.js:206 Compiler.applyPluginsAsyncSeries
[Sisketeers]/[tapable]/lib/Tapable.js:206:13
- Compiler.js:511 compilation.seal.err
[Sisketeers]/[webpack]/lib/Compiler.js:511:11
- Tapable.js:195 Compilation.applyPluginsAsyncSeries
[Sisketeers]/[tapable]/lib/Tapable.js:195:46
- Compilation.js:671 self.applyPluginsAsync.err
[Sisketeers]/[webpack]/lib/Compilation.js:671:19
- Tapable.js:195 Compilation.applyPluginsAsyncSeries
[Sisketeers]/[tapable]/lib/Tapable.js:195:46
- Compilation.js:662 self.applyPluginsAsync.err
[Sisketeers]/[webpack]/lib/Compilation.js:662:11
- Tapable.js:195 Compilation.applyPluginsAsyncSeries
[Sisketeers]/[tapable]/lib/Tapable.js:195:46
- Compilation.js:657 self.applyPluginsAsync.err
[Sisketeers]/[webpack]/lib/Compilation.js:657:10
- Tapable.js:195 Compilation.applyPluginsAsyncSeries
[Sisketeers]/[tapable]/lib/Tapable.js:195:46
- Compilation.js:653 sealPart2
[Sisketeers]/[webpack]/lib/Compilation.js:653:9
- Tapable.js:195 Compilation.applyPluginsAsyncSeries
[Sisketeers]/[tapable]/lib/Tapable.js:195:46
- Compilation.js:596 Compilation.seal
[Sisketeers]/[webpack]/lib/Compilation.js:596:8
- Compiler.js:508 applyPluginsParallel.err
[Sisketeers]/[webpack]/lib/Compiler.js:508:17
- Tapable.js:289
[Sisketeers]/[tapable]/lib/Tapable.js:289:11
- Compilation.js:498 _addModuleChain
[Sisketeers]/[webpack]/lib/Compilation.js:498:11
- Compilation.js:381 errorAndCallback.bail
[Sisketeers]/[webpack]/lib/Compilation.js:381:4
- Compilation.js:404 moduleFactory.create
[Sisketeers]/[webpack]/lib/Compilation.js:404:13
- NormalModuleFactory.js:235 factory
[Sisketeers]/[webpack]/lib/NormalModuleFactory.js:235:20
- NormalModuleFactory.js:60 resolver
[Sisketeers]/[webpack]/lib/NormalModuleFactory.js:60:20
- NormalModuleFactory.js:127 asyncLib.parallel
[Sisketeers]/[webpack]/lib/NormalModuleFactory.js:127:20
- async.js:3874
[Sisketeers]/[async]/dist/async.js:3874:9
- async.js:473
[Sisketeers]/[async]/dist/async.js:473:16
- async.js:1048 iteratorCallback
[Sisketeers]/[async]/dist/async.js:1048:13
- async.js:958
[Sisketeers]/[async]/dist/async.js:958:16
- async.js:3871
[Sisketeers]/[async]/dist/async.js:3871:13
Child html-webpack-plugin for "index.html":
ERROR in Entry module not found: Error: Can't resolve '/Users/jurdekker/Desktop/OnWeb/OnWeb.react/Sisketeers/dist/index.html' in '/Users/jurdekker/Desktop/OnWeb/OnWeb.react/Sisketeers'
Child extract-text-webpack-plugin node_modules/extract-text-webpack-plugin/dist node_modules/css-loader/index.js!node_modules/sass-loader/lib/loader.js!sass/main.scss:
[0] ./node_modules/css-loader!./node_modules/sass-loader/lib/loader.js!./sass/main.scss 1.27 kB {0} [built]
+ 1 hidden module
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! onweb-sisketeers#1.0.0 build: `webpack`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the onweb-sisketeers#1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/jurdekker/.npm/_logs/2018-01-19T17_33_37_060Z-debug.log
Jurs-MacBook-Pro:Sisketeers jurdekker$
I get this error the whole time but I do not know if it is up to webpack or something else. in my dist folder I get a .html file with the same error. I myself do not understand npm so if someone can give more information about it I would like to hear it.
Update 22-01-2018
this is my webpack config, I do not see anything wrong. maybe you find something?
const path = require('path');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry : './src/index.js',
output : {
filename : 'bundle.js',
path : path.resolve(__dirname, 'dist')
},
devtool : 'inline-source-map',
devServer : {
// contentBase : './dist'
historyApiFallback: true
},
module : {
rules : [
{
test : /\.(js|jsx)$/,
exclude : /(node_modules|bower_components)/,
use : {
loader : 'babel-loader',
options : {
presets : [ 'env', 'react', 'stage-2' ]
}
}
},
{
test : /\.scss$/,
use : ExtractTextPlugin.extract({
use : [ {
loader : "css-loader"
}, {
loader : "sass-loader"
} ],
// use style-loader in
// development
fallback : "style-loader"
})
}
]
},
plugins : [
new ExtractTextPlugin("styles.css"),
new HtmlWebpackPlugin({
template : path.join(path.resolve(__dirname, 'dist'), 'index.html')
})
],
resolve : {
extensions : [ '.js', '.jsx' ]
}
};
Webpack can't find some module. Need to check your webpack configs

Cannot find module environment when running in server side with Angular Universal

I have a simple Angular 4 app that I want to run in server side with Angular Universal (nodeJs server side rendering).
I followed these steps to configure the Angular Universal with the angular-cli help and it's all good until I try to use the angular environment.
When I try to access a property within the environment constant it works perfectly being rendered in client side (with ng serve) but in server side (ts-node src/server.ts) it throws the following error:
Error: Cannot find module 'environments/environment'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Dev\code-carama\src\app\auth.service.ts:3:1)
at Module._compile (module.js:571:32)
at Module.m._compile (C:\Dev\code-carama\node_modules\ts-node\src\index.ts:385:23)
at Module._extensions..js (module.js:580:10)
at Object.require.extensions.(anonymous function) [as .ts] (C:\Dev\code-carama\node_modules\ts-node\src\index.ts:388:12)
at Module.load (module.js:488:32)
npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v7.10.0
npm ERR! npm v4.2.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! code-carama#0.0.0 start: `ts-node src/server.ts`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the code-carama#0.0.0 start script 'ts-node src/server.ts'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the code-carama package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! ts-node src/server.ts
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs code-carama
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls code-carama
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\dima\AppData\Roaming\npm-cache\_logs\2017-06-05T12_00_03_595Z-debug.log
This is my server.ts:
import 'reflect-metadata';
import 'zone.js/dist/zone-node';
import { platformServer, renderModuleFactory } from '#angular/platform-server';
import { enableProdMode } from '#angular/core';
import { AppServerModuleNgFactory } from '../dist/ngfactory/src/app/app.server.module.ngfactory';
import * as express from 'express';
import { readFileSync } from 'fs';
import { join } from 'path';
const PORT = 4000;
enableProdMode();
const app = express();
let template = readFileSync(join(__dirname, '..', 'dist', 'index.html')).toString();
app.engine('html', (_, options, callback) => {
const opts = { document: template, url: options.req.url };
//it serves html from the compiled angular app from the server
renderModuleFactory(AppServerModuleNgFactory, opts)
.then(html => callback(null, html));
});
app.set('view engine', 'html');
app.set('views', 'src')
app.get('*.*', express.static(join(__dirname, '..', 'dist')));
app.get('*', (req, res) => {
res.render('index', { req });
});
app.listen(PORT, () => {
console.log(`listening on http://localhost:${PORT}!`);
});
And the simple service trying to access environment variables is the auth.service.ts:
import { Injectable } from '#angular/core';
import { environment } from 'environments/environment';
#Injectable()
export class AuthService {
private userManager = null;
constructor() {
console.log('AuthService instantiated in environment ' + environment.envName); //this will fail in server-side rendering
}
}
Any idea what's going with nodeJs (or angular universal) not to find that environment module?
Thanks
In projects Angular6 change 'environments/environment' by 'src/environments/environment'
Never mind, it seems the problem is that although for client side rendering the line:
import { environment } from 'environments/environment';
works well, for server side rendering the line must be:
import { environment } from '../environments/environment';
and by the way, I don't know why but by default for server-side rendering it will pick the PROD environment file.
on console: AuthService instantiated in environment prod
try to execute this commande npm run env and then execute ng serve. It's work with me
app.module.ts
Add this line:
import { environment } from '../environments/environment';
You just need to find the location of your environment.ts file.
With angular 14:
If you have your ts file here:
src\app\auth\reducers\index.ts
The answer is:
import { environment } from '../../../environments/environment';
Can you see environments folder in src folder?
And then, can you see environment.ts and environment.prod.ts on there?
If so, based on your depiction of the filesystem, you need to go back up one more level.
import { environment } from '../../environments/environment';
For me, some of build variants dev and prod were having some different const name
export const AppConfig {
instead of
export const environment {
Check that you do not have it ignored in the .gitignore
In your environment.ts add the following:
export const environment = {
production: false
};

Resources