Emit attempted before Angular Webpack plugin initialization after webpack5 build - webpack-5

I'm using Angular 14 ang webpack version: ^5.58.1.
Below is the config:
webpack.congif.js
const webpackPlugin = require('#ngtools/webpack').AngularWebpackPlugin;
module.exports = {
mode: 'development',
devtool: "source-map",
entry: {
main: "./js/main.js",
mainDrawer: "./js/divdrawer/main.ts",
polyfills: "./js/divdrawer/polyfills.ts",
entry: "./js/entry.js",
thirdpartylibs: "./js/thirdpartylibs.js"
},
output: {
path: path.join(__dirname, "build/"),
filename: "[name]bundle.js"
},
module: {
rules: [
{
parser: {
system: true,
}
}
test : /\.(tsx|ts)$/,
use: [
{
loader: '#ngtools/webpack',
options: {
configFile: path.resolve('./js/tsconfig.json')
},
},
]
},
},
plugins: [
new webpackPlugin({
tsconfig: './js/tsconfig.json',
}),
new webpack.ContextReplacementPlugin(
/\#angular(\\|\/)core(\\|\/)esm5/,
path.resolve(__dirname, "./js/divdrawer")
)
]
}
While generating the build I'm getting below error:
ERROR in ./js/divdrawer/filterMappingRemover.ts
Module build failed (from ./node_modules/#ngtools/webpack/src/index.js):
Error: Emit attempted before Angular Webpack plugin initialization.
at D:\MyProject\node_modules\#ngtools\webpack\src\ivy\loader.js:81:18
# ./js/entry.js 10:30-97
ERROR in ./js/divdrawer/main.ts
Module build failed (from ./node_modules/#ngtools/webpack/src/index.js):
Error: Emit attempted before Angular Webpack plugin initialization.
at D:\MyProject\node_modules\#ngtools\webpack\src\ivy\loader.js:81:18
at processTicksAndRejections (internal/process/task_queues.js:95:5)
ERROR in ./js/divdrawer/polyfills.ts
Module build failed (from ./node_modules/#ngtools/webpack/src/index.js):
Error: Emit attempted before Angular Webpack plugin initialization.
at D:\MyProject\node_modules\#ngtools\webpack\src\ivy\loader.js:81:18
ERROR in ./js/divdrawer/renderer.ts
Module build failed (from ./node_modules/#ngtools/webpack/src/index.js):
Error: Emit attempted before Angular Webpack plugin initialization.
at D:\MyProject\node_modules\#ngtools\webpack\src\ivy\loader.js:81:18
# ./js/entry.js 9:18-61
All the entries are throwing the errors with above message. As mentioned in webpack config we have multiple entries.
This is detected when I upgraded our project to angular 14.(Angular upgrade Steps: v10 --> v11--> v12--> v13/v14)
How to configure AngularWebpackPlugin correctly? Is there any alternative way?

For me this solution worked:
go to package.json and change your typescript version, If you want to upgrade your angular project to
Angular 15 (npm install typescript#"~4.8.0" --save-dev)
"devDependencies": {
...
"typescript": "~4.8.0"
}
Angular 14 (npm install typescript#"~4.7.0" --save-dev)
"devDependencies": {
...
"typescript": "~4.7.0"
}
Credit to F.R

yes downgrading typescript version to 4.8.2 resolve the issue.

For me, upgrading node version 16.xx to 18.xx (LTS) fixed the issue.

Related

guardReactiveProps warn in build with vite

I want to build my nuxt project with vite and rollup
and after I entered npm run build the build finishes successfully but it prints this warning:
"guardReactiveProps" is imported from external module "vue" but never used in "src/components/MyComponent.vue, and rest of my components!
please help me to fix this warning
here are my configs
package.json
"rollup": "^3.5.1",
"rollup-plugin-visualizer": "^5.8.3",
"vite": "^4.0.0",
vite.config.ts
import { resolve } from 'path'
import { defineConfig } from 'vite'
export default defineConfig({
build: {
rollupOptions: {
external: [
'bootstrap',
'bootstrap/js/dist/alert',
'bootstrap/js/dist/collapse',
'bootstrap/js/dist/modal',
'bootstrap/js/dist/offcanvas',
'bootstrap/js/dist/popover',
'bootstrap/js/dist/carousel',
'bootstrap/js/dist/dropdown',
'bootstrap/js/dist/tooltip',
'vue',
'#popperjs/core',
'#vueuse/core'
],
output: {
exports: 'named',
assetFileNames: `routaa-ui-kit.[ext]`, //without this, it generates build/styles.css
globals: {
vue: 'Vue',
bootstrap: 'Bootstrap',
'#vueuse/core': 'vueuse',
'bootstrap/js/dist/collapse': 'Collapse',
'bootstrap/js/dist/alert': 'Alert',
'bootstrap/js/dist/carousel': 'Carousel',
'bootstrap/js/dist/dropdown': 'Dropdown',
'bootstrap/js/dist/modal': 'Modal',
'bootstrap/js/dist/offcanvas': 'Offcanvas',
'bootstrap/js/dist/popover': 'Popover',
'bootstrap/js/dist/tooltip': 'Tooltip'
}
}
}
},
})
Thanks.

How to run Rails System tests in Heroku CI

How do I configure Heroku CI to run System tests?
This is my app.json, where I included what I thought would be the necessary buildpacks:
{
"environments": {
"test": {
"scripts": {
"test-setup": "bin/rails assets:precompile",
"test": "bin/rails test:system"
},
"addons":[
"heroku-postgresql:in-dyno"
],
"buildpacks": [
{ "url": "https://github.com/heroku/heroku-buildpack-google-chrome" },
{ "url": "heroku/nodejs" },
{ "url": "heroku/ruby"}
]
}
}
}
But when I deploy, I get the following error:
-----> Running test command `bin/rails test:system`...
rails aborted!
Webdrivers::BrowserNotFound: Failed to find Chrome binary.
I suspect I am missing something very basic....
I running Rails 6.0.1 and Ruby 2.6.3.
Did you setup your webdriver correctly to find the correct binary as mentioned on the official UAT wiki page of heroku?
Add gem 'webdrivers' to your Gemfile.
Add the following code snippet to your test_helper.rb (as stated on heroku buildback wiki and on webdrivers wiki):
require 'webdrivers' # Make sure webdrivers are loaded.
chrome_bin = ENV['GOOGLE_CHROME_SHIM'] if ENV['GOOGLE_CHROME_SHIM'].present?
chrome_capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: {
# You may want to use a different args
args: %w[headless disable-gpu window-size=1400x1400],
binary: chrome_bin
}
)
Capybara.register_driver :heroku_chrome do |app|
Capybara::Selenium::Driver.new(app, browser: :chrome, desired_capabilities: chrome_capabilities)
end
Afterwards tell your system test to use your custom chrome driver by adding it to your application_system_test_case.rb.
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :heroku_chrome
end

Test ES6 modules with Jest [duplicate]

This question already has answers here:
Does Jest support ES6 import/export?
(10 answers)
Closed 11 months ago.
How to test ES6 modules with Jest.
Example:
sum.js
const sum = function (a, b) {
return a + b;
}
export default sum;
sum.test.js
import sum from './sum';
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});
The only requirement is to config your test environment to Babel, and add the es2015 transform plugin:
Step 1:
Add your test environment to .babelrc in the root of your project:
{
"env": {
"test": {
"plugins": ["#babel/plugin-transform-modules-commonjs"]
}
}
}
Step 2:
Install the es2015 transform plugin:
npm install --save-dev #babel/plugin-transform-modules-commonjs
And that's it. Jest will enable compilation from ES modules to CommonJS automatically, without having to inform additional options to your jest property inside package.json.
The solutions above didn't work for me. I was able to solve with this:
yarn add --dev babel-jest #babel/core #babel/preset-env #babel/preset-typescript
babel.config.js
module.exports = {
presets: [
[
'#babel/preset-env',
{
targets: {
node: 'current',
},
},
],
'#babel/preset-typescript'
],
};
where I'm using typescript.
Reference.

Gulp unhandled error 182

I have a django blog project, and am trying to use bower to manage my packages.
When running 'gulp' from my console, I get the following error :
(py3) ➜ nomadpad git:(master) ✗ gulp
[15:16:15] Using gulpfile ~/code/nomadpad/gulpfile.js
[15:16:15] Starting 'css'...
[15:16:16] Finished 'css' after 1.23 s
[15:16:16] Starting 'html'...
[15:16:16] Finished 'html' after 3.38 ms
[15:16:16] Starting 'scripts'...
[15:16:16] Finished 'scripts' after 4.43 ms
[15:16:16] Starting 'default'...
[15:16:16] Finished 'default' after 38 μs
events.js:182
throw er; // Unhandled 'error' event
^
CssSyntaxError: /Users/davidmellor/code/nomadpad/bower_components/jquery/dist/jquery.js:756:9: Unknown word
at Input.error (/Users/davidmellor/code/nomadpad/node_modules/postcss/lib/input.js:119:22)
at Parser.unknownWord (/Users/davidmellor/code/nomadpad/node_modules/postcss/lib/parser.js:506:26)
at Parser.other (/Users/davidmellor/code/nomadpad/node_modules/postcss/lib/parser.js:171:18)
at Parser.parse (/Users/davidmellor/code/nomadpad/node_modules/postcss/lib/parser.js:84:26)
at parse (/Users/davidmellor/code/nomadpad/node_modules/postcss/lib/parse.js:24:16)
at new LazyResult (/Users/davidmellor/code/nomadpad/node_modules/postcss/lib/lazy-result.js:70:24)
at Processor.process (/Users/davidmellor/code/nomadpad/node_modules/postcss/lib/processor.js:117:12)
at /Users/davidmellor/code/nomadpad/node_modules/gulp-postcss/index.js:51:12
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:169:7)
My bower.json in the root folder looks like this :
{
"name": "blog_postcssgulp",
"description": "",
"main": "gulpfile.js",
"authors": [
"DMells <dave#davemellor.com>"
],
"license": "ISC",
"homepage": "https://github.com/DMells/nomadpad",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"jquery": "^3.3.1",
"modernizr": "^3.5.0"
}
}
I'm not sure what to do here, please can anyone assist?
Many thanks
If anyone else comes across this, I found the solution by removing my bower_components folder and then reinstalling bower, as well as the jquery package.
npm install bower --save-dev
And then the jquery package:
bower install jquery --save-dev

grunt.js ember-template-compiler not working

I have the grunt-ember-templates plugin, and it used to work. But I did a npm install and it got messed up. Now it does not compile.
The error is this:
Running "watch" task
Waiting...
>> File "resources\hbs\index\module.hbs" changed.
Running "emberTemplates:compile" (emberTemplates) task
>> ReferenceError: ember-template-compiler.js:22258
>> module.exports = Ember.__loader.require("ember-template-compiler");
>> ^
>> module is not defined
Warning: Ember Handlebars failed to compile resources/hbs/error.hbs. Use --force to continue.
Aborted due to warnings.
My Gruntfile.js looks somehow like this:
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
emberTemplates: {
compile: {
options: {
templateBasePath: /resources\/hbs\//,
// Path to the ember-template-compiler of my ember version
templateCompilerPath: 'resources/js/libs/ember-template-compiler.js',
handlebarsPath: 'node_modules/handlebars/dist/handlebars.js'
},
files: {
'resources/js/templates.js': 'resources/hbs/**/*.hbs'
}
}
},
...
Any idea? thanks in advance.
FWIW, it was just a dependency problem. Modifying the package.json to include the latest packages fixed it.