npm run build: ValidationError: Invalid options object. Copy Plugin - electron

I'm trying to package an electron app but I'm getting this error:
ValidationError: Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
- options[0] misses the property 'patterns'. Should be:
[non-empty string | object { from, to?, context?, globOptions?, toType?, force?, flatten?, transform?, cacheTransform?, transformPath?, noErrorOnMissing? }, ...] (should not have fewer than 1 item)
at validate (C:\Users\julis\Documents\prescription-data-entry-system\pdes\node_modules\copy-webpack-plugin\node_modules\schema-utils\dist\validate.js:96:11)
at new CopyPlugin (C:\Users\julis\Documents\prescription-data-entry-system\pdes\node_modules\copy-webpack-plugin\dist\index.js:24:30)
at Object.<anonymous> (C:\Users\julis\Documents\prescription-data-entry-system\pdes\.electron-vue\webpack.renderer.config.js:181:5)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (C:\Users\julis\Documents\prescription-data-entry-system\pdes\.electron-vue\build.js:14:24)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47 {
name: 'ValidationError',
errors: [
{
keyword: 'required',
dataPath: '[0]',
schemaPath: '#/required',
params: [Object],
message: "should have required property 'patterns'",
schema: [Object],
parentSchema: [Object],
data: [Object],
children: [Array]
}
],
schema: {
definitions: { ObjectPattern: [Object], StringPattern: [Object] },
type: 'object',
additionalProperties: false,
properties: { patterns: [Object], options: [Object] },
required: [ 'patterns' ]
},
headerName: 'Copy Plugin',
baseDataPath: 'options',
postFormatter: null,
message: 'Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.\n' +
" - options[0] misses the property 'patterns'. Should be:\n" +
' [non-empty string | object { from, to?, context?, globOptions?, toType?, force?, flatten?, transform?, cacheTransform?, transformPath?, noErrorOnMissing? }, ...] (should not have fewer than 1 item)'
}
In .electron-vue\webpack.renderer.config.js, I have:
new CopyWebpackPlugin([
{
from: path.join(__dirname, '../static'),
to: path.join(__dirname, '../dist/electron/static'),
ignore: ['.*']
}
]),
And changing it to below, doesn't resolve the error:
new CopyWebpackPlugin({
patterns: [
{ from: path.join(__dirname, '../static'), to: path.join(__dirname, '../dist/electron/static') },
],
}),
I'm not sure what the new pattern should be. I've looked at this question and tried to follow that pattern but that didn't work. How can I fix this?

I had to change the same thing in .electron-vue\webpack.web.config.js
/**
* Adjust webConfig for production settings
*/
if (process.env.NODE_ENV === 'production') {
webConfig.devtool = ''
webConfig.plugins.push(
new MinifyPlugin(),
new CopyWebpackPlugin({
//this is the new change
patterns: [
{ from: path.join(__dirname, '../static'), to: path.join(__dirname, '../dist/electron/static') },
],
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"'
}),
new webpack.LoaderOptionsPlugin({
minimize: true
})
)
}

Related

Transpile Turbo/Rails Turbo for IE 11

I have a rails app using Hotwire (Turbo & Stimulus). I'm trying to use webpack and babel to transpile JS for ES5/IE11. Stimulus and Turbo don't support IE11 any more, so I'm also trying to explicitly transpile them and then add required polyfills. My understanding is even if they've already been transpiled, the result should still be valid ES6 that can be transpiled again.
For Stimulus this approach appears to work fine but for Turbo I get
Uncaught TypeError: t.tagName is undefined
ht turbo.es2017-esm.js:1308
My best guess is that this is because Turbo is distributed as UMD modules so my babel config isn't transpiling it correctly. What's the best way to approach this?
browserlist:
"browserslist": {
"production": [
"last 1 version",
"> 1%",
"IE 10"
],
webpack.config.js:
const path = require("path")
const webpack = require("webpack")
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const RemoveEmptyScriptsPlugin = require('webpack-remove-empty-scripts')
const CopyPlugin = require("copy-webpack-plugin");
const mode = process.env.NODE_ENV === 'development' ? 'development' : 'production'
module.exports = {
mode,
devtool: "source-map",
entry: {
application: [
"./app/frontend/application.js",
]
},
module: {
rules: [
{
test: /\.(js|ts)$/,
include: [
path.resolve(__dirname, 'node_modules/#hotwired/turbo'),
path.resolve(__dirname, 'node_modules/#hotwired/turbo-rails'),
path.resolve(__dirname, 'node_modules/#hotwired/stimulus'),
path.resolve(__dirname, 'node_modules/#stimulus/polyfills'),
path.resolve(__dirname, 'node_modules/#rails/actioncable'),
path.resolve(__dirname, 'app/frontend'),
],
use: ['babel-loader'],
},
{
test: /\.(png|jpe?g|gif|eot|woff|woff2|ttf|svg|ico)$/i,
type: 'asset/resource'
},
{
test: /\.(scss|css)/i,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
}
],
},
resolve: {
modules: ['node_modules']
},
output: {
filename: "[name].js",
// we must set publicPath to an empty value to override the default of
// auto which doesn't work in IE11
publicPath: '',
path: path.resolve(__dirname, "app/assets/builds"),
},
plugins: [
new RemoveEmptyScriptsPlugin(),
new MiniCssExtractPlugin(),
new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }),
new CopyPlugin({
patterns: [
{ from: "node_modules/html5shiv/dist/html5shiv.min.js", to: "vendor" },
{ from: "app/frontend/vendor/outerHTML.js", to: "vendor" },
{ from: "app/frontend/vendor/polyfill-output-value.js", to: "vendor" }
],
}),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
jquery: 'jquery',
'window.jQuery': 'jquery'
})
]
}
babel.config.js
module.exports = function(api) {
var validEnv = ['development', 'test', 'production']
var currentEnv = api.env()
var isDevelopmentEnv = api.env('development')
var isProductionEnv = api.env('production')
var isTestEnv = api.env('test')
if (!validEnv.includes(currentEnv)) {
throw new Error(
'Please specify a valid `NODE_ENV` or ' +
'`BABEL_ENV` environment variables. Valid values are "development", ' +
'"test", and "production". Instead, received: ' +
JSON.stringify(currentEnv) +
'.'
)
}
return {
presets: [
isTestEnv && [
'#babel/preset-env'
],
(isProductionEnv || isDevelopmentEnv) && [
'#babel/preset-env',
{
forceAllTransforms: true,
useBuiltIns: 'entry',
corejs: '3.21.1',
modules: false,
exclude: ['transform-typeof-symbol']
}
]
].filter(Boolean),
plugins: [
'babel-plugin-macros',
'#babel/plugin-syntax-dynamic-import',
isTestEnv && 'babel-plugin-dynamic-import-node',
'#babel/plugin-proposal-class-properties',
'#babel/plugin-proposal-object-rest-spread',
'#babel/plugin-proposal-private-methods',
'#babel/plugin-proposal-private-property-in-object',
'#babel/plugin-transform-regenerator',
'#babel/plugin-transform-runtime',
[
'#babel/plugin-transform-spread',
{
loose: true
}
]
].filter(Boolean)
}
}

Monaca Editor syntax highlighting is ok, but editor doesn't show any errors

Syntax highlighting is ok, but doesn't show any errors.
Line 5 should show an error in red at end of the line in editor, but not.
Why could that be?
I'm using monaco webpack plugin, with these config.
index.js
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
import 'monaco-editor/esm/vs/basic-languages/javascript/javascript';
import 'monaco-editor/esm/vs/basic-languages/python/python';
monaco.editor.create(document.getElementById('duzenleyici'), {
value: ``,
language: 'python',
theme: 'vs-dark',
wordWrap: true,
automaticLayout: true,
});
webpack-config.js
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
const path = require('path');
module.exports = {
entry: './index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'monaco.js',
},
module: {
rules: [
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.ttf$/,
use: ['file-loader'],
},
],
},
plugins: [
new MonacoWebpackPlugin({
languages: ['javascript', 'python'],
features: ['find', 'bracketMatching', 'comment', 'folding', 'suggest', 'contextmenu', 'coreCommands', 'codeAction', 'clipboard', 'linesOperations', 'suggest', 'wordHighlighter'],
globalAPI: true,
// publicPath: '/',
}),
],
};
In index.js :
`
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
// validation settings
monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions({
noSemanticValidation: false,
});
// compiler options
monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
target: monaco.languages.typescript.ScriptTarget.ES6,
allowNonTsExtensions: true
});
`
In webpack-config.js plugins key:
new MonacoWebpackPlugin({
languages: ['javascript', 'typescript']
})

Nestjs - Typeorm custom connection name

I have a Nestjs db Module and it works perfectly
#Module({
imports: [
TypeOrmModule.forRootAsync({
useFactory: () => {
return {
name: 'default', // <=== here
type: "mysql",
...
};
},
}),
TypeOrmModule.forFeature(entities, 'default'), // <=== here
],
exports: [TypeOrmModule],
})
export class DBModule {}
if I change the connection name to anything else rather then 'default' say 'test' I get an error
#Module({
imports: [
TypeOrmModule.forRootAsync({
useFactory: () => {
return {
name: 'test', // <=== here
type: "mysql",
...
};
},
}),
TypeOrmModule.forFeature(entities, 'test'), // <=== here
],
exports: [TypeOrmModule],
})
export class DBModule {}
[Nest] 10746 - 05/15/2021, 5:55:34 PM [ExceptionHandler] Nest can't resolve dependencies of the test_UserEntityRepository (?). Please make sure that the argument testConnection at index [0] is available in the TypeOrmModule context.
Potential solutions:
- If testConnection is a provider, is it part of the current TypeOrmModule?
- If testConnection is exported from a separate #Module, is that module imported within TypeOrmModule?
#Module({
imports: [ /* the Module containing testConnection */ ]
})
The error seams to only show up if I use TypeOrmModule.forRootAsync
For TypeOrmModule.forRoot if works!
Is there any different way to indicate the connection name? I need to add another connection and can't do it because of this error. Really would like to use 'forRootAsync'
Pass the connection name as follows.
#Module({
imports: [
TypeOrmModule.forRootAsync({
name: 'test', // <=== here
useFactory: () => {
return {
type: "mysql",
...
};
},
}),
TypeOrmModule.forFeature(entities, 'test'), // <=== here
],
exports: [TypeOrmModule],
})
export class DBModule {}

What is the proper way to add files to a packaged electron app?

How do I put a a custom file into the root folder of an electron package when building?
I'm trying to add a file to the root of my electron app when it's packaged. Below is what I currently have. It works to an extent, but then code-signing fails.
export const packagerOptions = {
name: 'app',
platform: 'win32',
arch: 'x64',
dir: path.join(__dirname, '../'),
out: path.join(__dirname, '../dist/packaged'),
ignore: [
/^\/(build|e2e|src)($|\/)/,
/^\/dist\/(installer|packaged)($|\/)/,
/^\/node_modules\/edge\/(build|test)($|\/)/,
/^\/node_modules\/edge\/.+\\.(dll|node)$/,
/^\/node_modules\/electron-edge-js\/(?!.+8\.9\.3).+\.(dll|node)$/,
],
icon: path.join(__dirname, '../assets/win32/app.ico'),
asar: {
unpack: '*.{dll,ico,node}'
},
prune: true,
overwrite: true,
win32metadata: {
CompanyName: 'App Co',
FileDescription: 'App Desktop',
ProductName: 'App Desktop',
InternalName: 'App Desktop'
},
afterExtract: [safeFFMPEG],
afterCopy: [serialHooks([
(buildPath, electronVersion, platform, arch, callback) => {
fs.copyFile(
path.join(__dirname, '../assets/extraResources/MYFILE'),
path.join(buildPath, '..', '..', 'MYFILE'),
err => console.log(err, 'an error occurred'));
}
])],
};
I've tried using:
extraResource: [
path.join(__dirname, '../assets/extraResources/MYFILE')
],
but that puts it in the resources/ folder. I need it to be in the parent folder of resources.

WebPack - ExtractTextPlugin.extract - Module build failed: No input specified: provide a file name or a source string to process

I've just upgraded to the latest WebPack and my existing configuration throws up an error, I have tracked down which code causes the issue, but not sure how to resolve it.
I have tracked the error down to here
{
test: /\.(css|scss)$/,
loaders: ExtractTextPlugin.extract({
fallbackLoader: 'style',
loader: 'css?minimize!sass!postcss'
})
},
Entries from Package.json
"webpack": "2.2.1",
"extract-text-webpack-plugin": "^2.0.0-beta.3",
"html-webpack-plugin": "^2.24.1",
Error
ERROR in ./~/css-loader?minimize!./~/sass-loader/lib/loader.js!./~/postcss-loader!./src/index.scss
Module build failed: No input specified: provide a file name or a source string to process
# ./src/index.scss 4:14-172
# ./src/main.ts
ERROR in ./src/index.scss
Module build failed: ModuleBuildError: Module build failed: No input specified: provide a file name or a source string to process
at d:\workible\data-extractor\app-client\node_modules\webpack\lib\NormalModule.js:137:35
at d:\workible\data-extractor\app-client\node_modules\loader-runner\lib\LoaderRunner.js:364:11
at d:\workible\data-extractor\app-client\node_modules\loader-runner\lib\LoaderRunner.js:230:18
at context.callback (d:\workible\data-extractor\app-client\node_modules\loader-runner\lib\LoaderRunner.js:111:13)
at Object.asyncSassJobQueue.push [as callback] (d:\workible\data-extractor\app-client\node_modules\sass-loader\lib\loader.js:51:13)
at d:\workible\data-extractor\app-client\node_modules\sass-loader\node_modules\async\dist\async.js:2234:31
at apply (d:\workible\data-extractor\app-client\node_modules\sass-loader\node_modules\async\dist\async.js:20:25)
at d:\workible\data-extractor\app-client\node_modules\sass-loader\node_modules\async\dist\async.js:56:12
at d:\workible\data-extractor\app-client\node_modules\sass-loader\node_modules\async\dist\async.js:840:16
at module.exports.render (d:\workible\data-extractor\app-client\node_modules\node-sass\lib\index.js:375:5)
at d:\workible\data-extractor\app-client\node_modules\sass-loader\node_modules\async\dist\async.js:3894:5
at process (d:\workible\data-extractor\app-client\node_modules\sass-loader\node_modules\async\dist\async.js:2299:17)
at Immediate.<anonymous> (d:\workible\data-extractor\app-client\node_modules\sass-loader\node_modules\async\dist\async.js:2112:16)
at runCallback (timers.js:649:20)
at tryOnImmediate (timers.js:622:5)
at processImmediate [as _immediateCallback] (timers.js:594:5)
ERROR in d:\workible\data-extractor\app-client\node_modules\extract-text-webpack-plugin\loader.js!d:\workible\data-extractor\app-client\node_modules\style-loader\index.js!d:\workible\data-extractor\app-client\node_modules\css-loader\index.js?minimize!d:\workible\data-extractor\app-client\node_modules\sass-loader\lib\loader.js!d:\workible\data-extractor\app-client\node_modules\postcss-loader\index.js!d:\workible\data-extractor\app-client\src\index.scss doesn't export content
WebPack Configuration
const webpack = require('webpack');
const conf = require('./gulp.conf');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const autoprefixer = require('autoprefixer');
module.exports = {
module: {
loaders: [
{
test: /.json$/,
loaders: [
'json'
]
},
{
test: /\.(css|scss)$/,
loaders: ExtractTextPlugin.extract({
fallbackLoader: 'style',
loader: 'css?minimize!sass!postcss'
})
},
{
test: /\.ts$/,
exclude: /node_modules/,
loaders: [
'ts'
]
},
{
test: /.html$/,
loaders: [
'html'
]
}
]
},
plugins: [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.NoErrorsPlugin(),
new HtmlWebpackPlugin({
template: conf.path.src('index.html')
}),
new webpack.ContextReplacementPlugin(
/angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
conf.paths.src
),
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"'
}),
new webpack.optimize.UglifyJsPlugin({
compress: {unused: true, dead_code: true, warnings: false} // eslint-disable-line camelcase
}),
new ExtractTextPlugin('query-[contenthash].css'),
new webpack.optimize.CommonsChunkPlugin({name: 'vendor'})
],
postcss: () => [autoprefixer],
output: {
path: path.join(process.cwd(), conf.paths.dist),
filename: '[name]-[hash].js'
},
resolve: {
extensions: [
'',
'.webpack.js',
'.web.js',
'.js',
'.ts'
]
},
entry: `./${conf.path.src('main')}`,
ts: {
configFileName: 'tsconfig.json'
},
tslint: {
configuration: require('../tslint.json')
}
};
Added Some CSS to my .scss file as per #ickiir
body {}
Now the Error has advanced to
ERROR in ./src/index.scss
Module build failed: ReferenceError: window is not defined
at d:\workible\data-extractor\app-client\node_modules\style-loader\index.js!d:\workible\data-extractor\app-client\node_modules\css-loader\index.js?minimize!d:\workible\data-extractor\app-client\node_modules\sass-loader\lib\loader.js!d:\workible\data-extractor\app-client\node_modules\postcss-loader\index.js!d:\workible\data-extractor\app-client\src\index.scss:99:30
at d:\workible\data-extractor\app-client\node_modules\style-loader\index.js!d:\workible\data-extractor\app-client\node_modules\css-loader\index.js?minimize!d:\workible\data-extractor\app-client\node_modules\sass-loader\lib\loader.js!d:\workible\data-extractor\app-client\node_modules\postcss-loader\index.js!d:\workible\data-extractor\app-client\src\index.scss:94:47
at module.exports (d:\workible\data-extractor\app-client\node_modules\style-loader\index.js!d:\workible\data-extractor\app-client\node_modules\css-loader\index.js?minimize!d:\workible\data-extractor\app-client\node_modules\sass-loader\lib\loader.js!d:\workible\data-extractor\app-client\node_modules\postcss-loader\index.js!d:\workible\data-extractor\app-client\src\index.scss:116:68)
at Object.<anonymous> (d:\workible\data-extractor\app-client\node_modules\style-loader\index.js!d:\workible\data-extractor\app-client\node_modules\css-loader\index.js?minimize!d:\workible\data-extractor\app-client\node_modules\sass-loader\lib\loader.js!d:\workible\data-extractor\app-client\node_modules\postcss-loader\index.js!d:\workible\data-extractor\app-client\src\index.scss:400:36)
at __webpack_require__ (d:\workible\data-extractor\app-client\node_modules\style-loader\index.js!d:\workible\data-extractor\app-client\node_modules\css-loader\index.js?minimize!d:\workible\data-extractor\app-client\node_modules\sass-loader\lib\loader.js!d:\workible\data-extractor\app-client\node_modules\postcss-loader\index.js!d:\workible\data-extractor\app-client\src\index.scss:21:30)
at d:\workible\data-extractor\app-client\node_modules\style-loader\index.js!d:\workible\data-extractor\app-client\node_modules\css-loader\index.js?minimize!d:\workible\data-extractor\app-client\node_modules\sass-loader\lib\loader.js!d:\workible\data-extractor\app-client\node_modules\postcss-loader\index.js!d:\workible\data-extractor\app-client\src\index.scss:65:18
at Object.<anonymous> (d:\workible\data-extractor\app-client\node_modules\style-loader\index.js!d:\workible\data-extractor\app-client\node_modules\css-loader\index.js?minimize!d:\workible\data-extractor\app-client\node_modules\sass-loader\lib\loader.js!d:\workible\data-extractor\app-client\node_modules\postcss-loader\index.js!d:\workible\data-extractor\app-client\src\index.scss:68:10)
at Module._compile (module.js:570:32)
at Object.exec (d:\workible\data-extractor\app-client\node_modules\webpack\lib\NormalModule.js:94:6)
at Object.<anonymous> (d:\workible\data-extractor\app-client\node_modules\extract-text-webpack-plugin\loader.js:112:21)
at Compiler.<anonymous> (d:\workible\data-extractor\app-client\node_modules\webpack\lib\Compiler.js:251:10)
at d:\workible\data-extractor\app-client\node_modules\webpack\lib\Compiler.js:442:12
at next (d:\workible\data-extractor\app-client\node_modules\tapable\lib\Tapable.js:138:11)
at Compiler.<anonymous> (d:\workible\data-extractor\app-client\node_modules\extract-text-webpack-plugin\loader.js:93:4)
at next (d:\workible\data-extractor\app-client\node_modules\tapable\lib\Tapable.js:140:14)
at Compiler.<anonymous> (d:\workible\data-extractor\app-client\node_modules\ts-loader\dist\after-compile.js:11:13)
ERROR in d:\workible\data-extractor\app-client\node_modules\extract-text-webpack-plugin\loader.js!d:\workible\data-extractor\app-client\node_modules\style-loader\index.js!d:\workible\data-extractor\app-client\node_modules\css-loader\index.js?minimize!d:\workible\data-extractor\app-client\node_modules\sass-loader\lib\loader.js!d:\workible\data-extractor\app-client\node_modules\postcss-loader\index.js!d:\workible\data-extractor\app-client\src\index.scss doesn't export content
I finally resolved this issue by doing the following.
I made sure that my index.scss file was not empty by adding the following (as per #ickyrr)
body {}
And I removed the fallbackLoader
{
test: /\.(css|scss)$/,
loaders: ExtractTextPlugin.extract({
//fallbackLoader: 'style',
loader: 'css?minimize!sass!postcss'
})
},
As of webpack version 2.2.1 there is a syntax change... so instead of using loader or loaders the correct syntax would be 'use'
here is an example:
BEFORE:
{
test: /\.(scss|sass)$/,
include: helpers.root('src/app'),
exclude: [/\.global\.(scss|sass)$/, 'src'],
loaders: ['raw-loader?sourceMap', 'sass-loader?sourceMap']
},
AFTER:
{
test: /\.(scss|sass)$/,
include: helpers.root('src/app'),
exclude: [/\.global\.(scss|sass)$/, 'src'],
use: ['raw-loader?sourceMap', 'sass-loader?sourceMap']
},
Webpack 2 is sooo complicated. After messing around with it for an hour, the following works for me for scss.
{
test:/\.scss$/,
use:ExtractTextPlugin.extract({fallback:"style-loader",use:["css-loader","sass-loader"]}),
include:path.join(__dirname,"client/src"),
},
I reviewed many code samples before I tried the above. Hope this helps.

Resources