i create project in angular 6 using angular cli tool but it gives error import * as fs from 'fs'; - angular6

i create project in angular 6 using angular cli tool but it gives error when i import * as fs from 'fs'(integrate electron app). The error message Module not found: Error: Cannot resolve module 'fs'

I assume you're using node.
Are you using webpack? If so see
here
The solution is to add
node: {
fs: 'empty'
}
to your webpack config.
If that doesn't work, try changing your import statement to a require:
const fs = require('fs');, as the node documentation recommends.

Related

require('react') vs require('React')

The following code in external node_modules is not working:
var _react = require('react');
But:
var _react = require('React');
works. Now I have a problem that in some node_modules it is required with 'react', and then I get this error:
Uncaught Error: Cannot find module 'react'
I am using gulp as build tool.
What can I do so that both requires will work?
Do you have 'React' added in your package.json ?
If not, add: "react": "17.0.2" (or another React version)
Try running the command:
npm install
And try again
Require is not a React api. Try this syntax:
import React from 'react'

Webpack can't import a .json file when using alias / aliased paths

I am using Webpack's native json importer to import a json file as a javascript object:
import config from "./config.json"
Works fine - problem is, when I add an alias to the webpack configuration:
resolve: {
alias: {
"#data": path.resolve(__dirname, "src/js/data/"),
},
},
Importing the json file via the aliased path does not seem to work anymore:
import config from "#data/config.json
ERROR in ...
Module not found: Error: Can't resolve '#alias/file.json' in ...
Is there any trick to get Webpack's native json importer to play nice with aliased paths?
I had to add the extensions field to the resolve configuration and include ".json" in the array - after doing that both import config from "#data/config (as the extensions is resolved automatically) and import config from "#data/config.json seem to work fine.

Babel dependency not resolved in react app created using "create-react-app" utility

I have created a react-app using create-react-app utility but when I import a node module then it gives me error stating :
./node_modules/#nross/react-vega/src/VegaLite.js
Module parse failed: Unexpected token (17:2)
You may need an appropriate loader to handle this file type.
| onParseError,
| children,
| ...otherProps
| }) => {
| const adjustedSpec = { ...spec };
And when I import babel-loader into the file where I am importing the node module then it is giving me the error:-
Failed to compile.
./node_modules/babel-core/lib/helpers/resolve.js
Module not found: Can't resolve 'module' in 'C:\VegaDemo\my-app\node_modules\babel-core\lib\helpers'.
You need to eject in order to customize the boilerplate.
Simply run
npm run eject
Or
yarn run eject
If you use yarn.
Then, install your npm module and run
npm run install
Without eject, the boilerplate is locked up.

laravel blade templates minifier using laravel-mix # laravel 5.4

As of laravel 5.4, they are no longer using gulp but rather webpack, and they no longer use laravel-elixir but rather a new package they called laravel-mix, now I use a package called laravel-elixir-blade-minifier which minifies laravel-blade templates, how do I use it with now with laravel-mix? I mean, I'm getting confused here.
you can try: https://github.com/hiseanchang/laravel-mix-template-minifier
npm install --save-dev laravel-mix-template-minifier
// webpack.mix.js
let mix = require('laravel-mix');
mix.minTemplate = require('laravel-mix-template-minifier')
if (mix.inProduction()) {
mix.minTemplate('storage/framework/views/*.php', 'storage/framework/views/')
}

How to setup google-closure-compiler to recognize NodeJs core modules

I am trying to setup my google-closure-compiler to be able to read my files which uses Node core modules and I read online that I need the NodeJS externs... I downloaded a set of externs from: https://github.com/dcodeIO/node.js-closure-compiler-externs (which is like 2 years old??) and then in the compiler option I added the following in my gulpfile.js:
process_common_js_modules: true,
externs: '../node.js-closure-compiler-externs/fs.js',
When running gulp I get:
[19:38:07] gulp-google-closure-compiler: /src/js/myfile.js:3: ERROR - Failed to load module "fs"
const fs = require('fs');
What is really the right way to setup a JavaScript project that uses Node.js and have google-closure-compiler regconize things properly? Is there a step by step tutorial somewhere?