Migrating ngFileSaver from bower to node package breaks - bower

I have an Angular 1.6 project which did build using:
node 10.16.0
bower 1.8.14
gulp 3.9.1
and with the command sequence:
npm install
bower install
gulp
It now breaks at the bower install step with the file-saver.js#~1.20150507.2 throwing error:
Failed to execute "git ls-remote --tags --heads https://github.com/Teleborder/FileSaver.js.git", exit code of #128
Because of this, I have removed the line
"angular-file-saver": "^1.1.3"
from the bower.json file (bower uninstall did not work for that package) and installed the angular-file-saver package via
npm install angular-file-saver --save-dev
So now the package.json looks like this:
{
"name": "app",
"version": "1.0.0",
"description": "app",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"app"
],
"author": "me",
"license": "ISC",
"devDependencies": {
"angular-file-saver": "^1.1.3",
"del": "^2.2.2",
"eslint-config-angular": "^0.5.0",
"eslint-plugin-angular": "^1.5.0",
"gulp": "^3.9.1",
"gulp-angular-filesort": "^1.1.1",
"gulp-angular-templatecache": "^2.0.0",
"gulp-autoprefixer": "^3.1.1",
"gulp-cheerio": "^0.6.2",
"gulp-clean-css": "^2.2.2",
"gulp-concat": "^2.6.1",
"gulp-eslint": "^3.0.1",
"gulp-filter": "^4.0.0",
"gulp-flatten": "^0.3.1",
"gulp-htmlmin": "^3.0.0",
"gulp-if": "^2.0.2",
"gulp-inject": "^4.1.0",
"gulp-ng-annotate": "^2.0.0",
"gulp-rev": "^7.1.2",
"gulp-sass": "^3.0.0",
"gulp-sourcemaps": "^1.9.1",
"gulp-string-replace": "^0.3.1",
"gulp-uglify": "^2.0.0",
"main-bower-files": "^2.13.1",
"natives": "^1.1.6",
"require-dir": "^0.3.1",
"rimraf": "^2.6.2",
"stream-series": "^0.1.1",
"uglify-save-license": "^0.4.1",
"yargs": "^6.5.0"
},
"dependencies": {
"bower": "^1.8.4"
}
}
My src\app.js contains this:
(function(angular) {
'use strict';
angular
.module('app', [
'angular-cache',
'ui.router',
'ui.router.modal',
'ui.bootstrap',
'ui.bootstrap-slider',
'ui.validate',
'angular-confirm',
'ngAnimate',
'ngFileSaver',
'angularMoment',
'pascalprecht.translate',
'tmh.dynamicLocale']);
}(window.angular));
And my controller contains this:
angular
.module('app')
.component('readings', {
controllerAs: 'vm',
templateUrl: 'readings/readings.html',
controller: ReadingsController
});
function ReadingsController(..., FileSaver, ...) {
So, now this command sequence works:
npm install
bower install
gulp
But I get this error in the browser
Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to:
Error: [$injector:modulerr] Failed to instantiate module ngFileSaver due to:
Error: [$injector:nomod] Module 'ngFileSaver' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.6.0/$injector/nomod?p0=ngFileSaver
How can I get this package working via npm instead of bower?

Related

error Command failed with exit code 1 with react-native and Xcode library not found

I'm getting the following error when I clone react native project from github, yarn install, cd ios && pod install, cd .. , yarn ios . And/or when I ran react-native run-ios as well:
info Run CLI with --verbose flag for more details.
error Command failed with exit code 1.
In addition, when I open the .xcworkspace in the Xcode, I get the error:
library not found for BugsnagReactNative
The package.json is:
{
"name": "proj",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"build": "CI= npm run build",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"#bugsnag/react-native": "^7.16.2",
"#react-native-async-storage/async-storage": "^1.15.6",
"#react-native-community/checkbox": "^0.5.8",
"#react-native-community/datetimepicker": "^4.0.1",
"#react-native-community/masked-view": "^0.1.11",
"#react-native-community/netinfo": "^6.0.0",
"#react-navigation/bottom-tabs": "^6.0.5",
"#react-navigation/native": "^6.0.2",
"#react-navigation/stack": "^6.0.7",
"amazon-cognito-identity-js": "^5.1.0",
"aws-amplify": "^4.2.4",
"axios": "^0.21.1",
"package": "^1.0.1",
"prop-types": "^15.7.2",
"react": "17.0.2",
"react-native": "0.66.3",
"react-native-carousel": "^0.12.0",
"react-native-codegen": "^0.0.7",
"react-native-collapsible": "^1.6.0",
"react-native-date-picker": "^4.1.1",
"react-native-dropdown-picker": "^5.1.23",
"react-native-exit-app": "^1.1.0",
"react-native-gesture-handler": "^1.10.3",
"react-native-keyboard-aware-scroll-view": "^0.9.5",
"react-native-mask-input": "^1.0.3",
"react-native-modal-dropdown": "^1.0.1",
"react-native-month-year-picker": "^1.8.0",
"react-native-safe-area-context": "^3.3.0",
"react-native-screens": "^3.13.1",
"react-native-select-dropdown": "^1.1.0",
"react-native-snap-carousel": "^3.9.1",
"tcomb-form-native": "^0.6.20",
"toggle-switch-react-native": "^3.2.0",
"yarn": "^1.22.17"
},
"devDependencies": {
"#babel/core": "^7.15.0",
"#babel/runtime": "^7.15.3",
"#bugsnag/source-maps": "^2.3.1",
"#react-native-community/eslint-config": "^3.0.0",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "26.6.3",
"eslint": "7.32.0",
"jest": "^27.0.6",
"metro-react-native-babel-preset": "^0.66.2",
"react-test-renderer": "17.0.2"
},
"jest": {
"preset": "react-native"
}
}
The solutions below I tried didn't work.
yarn add global #bugsnag/react-native-cli
change rct-folly deployment target to 9.0
set Build Active architecture Only to Yes
click and install ios 13.0 simulator in xcode
delete the search paths in build settings delete pods folder, and installed pods again
remove all lines in the 'Other Linker Flags' list BUT only if $(inherited) is at the top
pod update
reinstall ruby/gem
uninstall and reinstall Cocoapods
rm -rf node_modules, yarn cache clean
remove the podfile.lock and the pod, re-install them
sudo arch -x86_64 gem install ffi, arch -x86_64 pod install
uninstall and reinstall watchman
check node version, react native version, and bugsnag version
comment out bugsnag dependencies from package. json
fresh install multiple times
try this
npx #bugsnag/react-native-cli init
and check bugsnag documentation as you need to have a project available on bugsnag

Getting Error: Cannot find module 'cypress-mochawesome-reporter/plugin' when i run cypress in docker

I have never used docker before. When I run it in my local it will be working fine but when I run using docker getting an error. I have created a docker file that contains the below line of code.
FROM cypress/base:14.19.0
RUN mkdir /legrande-cypress
WORKDIR /legrande-cypress
COPY ./package.json .
COPY ./cypress.json .
COPY ./cypress ./cypress
RUN npm install
ENTRYPOINT ["npx","cypress","run"]
This 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 ############################"
},
"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-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"
}
}
When I run cypress test using docker run -i -v "%cd%":/legrande-cypress -t cypress-image:latest --spec cypress/integration/examples/*.js it will throwes an error below.
Your pluginsFile threw an error from: /legrande-cypress/cypress/plugins/index.js
Error: Cannot find module 'cypress-mochawesome-reporter/plugin'
Require stack:
- /legrande-cypress/cypress/plugins/index.js
- /root/.cache/Cypress/9.5.1/Cypress/resources/app/packages/server/lib/plugins/child/run_plugins.js
- /root/.cache/Cypress/9.5.1/Cypress/resources/app/packages/server/lib/plugins/child/index.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:101:18)
at module.exports (/legrande-cypress/cypress/plugins/index.js:22:3)
at /root/.cache/Cypress/9.5.1/Cypress/resources/app/packages/server/lib/plugins/child/run_plugins.js:94:12
at tryCatcher (/root/.cache/Cypress/9.5.1/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/util.js:16:23)
at Function.Promise.attempt.Promise.try (/root/.cache/Cypress/9.5.1/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/method.js:39:29)
at load (/root/.cache/Cypress/9.5.1/Cypress/resources/app/packages/server/lib/plugins/child/run_plugins.js:91:7)
at EventEmitter.<anonymous> (/root/.cache/Cypress/9.5.1/Cypress/resources/app/packages/server/lib/plugins/child/run_plugins.js:209:5)
at EventEmitter.emit (events.js:400:28)
at process.<anonymous> (/root/.cache/Cypress/9.5.1/Cypress/resources/app/packages/server/lib/plugins/util.js:19:22)
at process.emit (events.js:400:28)
at emit (internal/child_process.js:912:12)
at processTicksAndRejections (internal/process/task_queues.js:83:21)
How to resolve this error please let me know if anyone has any idea.

Rails Webpacker React: /bin/webpack-dev-server The command moved into a separate package: #webpack-cli/serve

Today I create a fresh Rails webpacker app with command:
$ rails new my-app --webpacker=react -d mysql
The fresh app generated smoothly until I tried to run:
$ ./bin/webpack-dev-server
The webpack-cli return a message:
The command moved into a separate package: #webpack-cli/serve
Would you like to install serve? (That will run yarn add -D #webpack-cli/serve) (yes/NO) :
I tried to select yes but the installation of webpack-cli is not success with message:
success Saved lockfile.
success Saved 1 new dependency.
info Direct dependencies
└─ #webpack-cli/serve#1.5.2
info All dependencies
└─ #webpack-cli/serve#1.5.2
Done in 2.11s.
TypeError: Class constructor ServeCommand cannot be invoked without 'new'
at runWhenInstalled (/home/yohanes/Projects/my-app/node_modules/webpack-cli/bin/utils/prompt-command.js:46:9)
at /home/yohanes/Projects/my-app/node_modules/webpack-cli/bin/utils/prompt-command.js:124:15
at processTicksAndRejections (internal/process/task_queues.js:95:5)
and when I run ./bin/webpack-dev-server command I get error messages:
/home/yohanes/Projects/my-app/node_modules/webpack-cli/bin/utils/prompt-command.js:46
return func(...args);
^
TypeError: Class constructor ServeCommand cannot be invoked without 'new'
at runWhenInstalled (/home/yohanes/Projects/my-app/node_modules/webpack-cli/bin/utils/prompt-command.js:46:9)
at promptForInstallation (/home/yohanes/Projects/my-app/node_modules/webpack-cli/bin/utils/prompt-command.js:140:10)
at /home/yohanes/Projects/my-app/node_modules/webpack-cli/bin/cli.js:32:43
at Object.<anonymous> (/home/yohanes/Projects/my-app/node_modules/webpack-cli/bin/cli.js:366:3)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Module.require (internal/modules/cjs/loader.js:961:19)
at require (internal/modules/cjs/helpers.js:92:18)
Here is my package.json:
{
"name": "my-app",
"private": true,
"dependencies": {
"#babel/preset-react": "^7.14.5",
"#rails/actioncable": "^6.0.0",
"#rails/activestorage": "^6.0.0",
"#rails/ujs": "^6.0.0",
"#rails/webpacker": "5.4.2",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"prop-types": "^15.7.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"turbolinks": "^5.2.0",
"webpack": "^4.46.0",
"webpack-cli": "^3.3.12"
},
"version": "0.1.0",
"devDependencies": {
"webpack-dev-server": "^4.0.0"
}
}
and my node.js version
$ node -v
v14.17.5
For now, temporarily I solve it by using the previous version:
"devDependencies": {
"webpack-dev-server": "^3.11.2"
}
Update:
The webpack-cli & webpack-dev-server at devDependencies of fresh package.json generated by using rails new my-app --webpacker=react are:
"dependencies": {
...
"webpack-cli": "^3.3.12"
...
},
"devDependencies": {
"webpack-dev-server": "^4.0.0"
}
If we see from here, we found that webpack-dev-server v.4.0.0 depends on "webpack-cli": "^4.7.2" which is incompatible with fresh rails webpacker package configurations that use "webpack-cli": "^3.3.12" as dependency.
Usually we can check webpack-cli info by using command npx webpack-cli info. But now when I try, I got an error and found a warning:
$ npx webpack-cli info
...
warning " > #webpack-cli/info#1.3.0" has incorrect peer dependency "webpack-cli#4.x.x".
...
TypeError: Class constructor InfoCommand cannot be invoked without 'new'
at runWhenInstalled (/home/yohanes/Projects/my-app/node_modules/webpack-cli/bin/utils/prompt-command.js:46:9)
at /home/yohanes/Projects/my-app/node_modules/webpack-cli/bin/utils/prompt-command.js:124:15
at processTicksAndRejections (internal/process/task_queues.js:95:5)
...
For now, the only configurations that work with my environment only:
"dependencies": {
...
"webpack-cli": "^3.3.12"
...
},
"devDependencies": {
"webpack-dev-server": "^3.11.2"
}
Update:
Please see DHH comment here
Case close.

Webpack Compile: Cannot find module '#babel/preset-env' when deploy production

i use capistrano to deploy my rails project( Rails 6.0.0, Ruby 2.6.0)
i get bellow log when start `bundle exec cap production deploy
ERROR in ./app/javascript/packs/application.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Cannot find module '#babel/preset-env'
and
ERROR in ./app/javascript/packs/server_rendering.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Cannot find module '#babel/preset-env'
But when i test in local RAILS_ENV=production bundle exec rails assets:precompile . It built successful
my package.json
{
"name": "my_app_name",
"private": true,
"dependencies": {
"#babel/preset-react": "^7.0.0",
"#rails/actiontext": "^6.0.0",
"#rails/webpacker": "^4.0.2",
"axios": "^0.19.0",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"core-js": "2",
"prop-types": "^15.7.2",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react_ujs": "^2.6.0",
"trix": "^1.0.0",
"webpack-dev-server": "^3.3.1"
},
"devDependencies": {
"#babel/preset-env": "^7.7.6",
"babel-preset-env": "^1.7.0",
"webpack-dev-server": "^3.3.1"
}
}
my app/javascript/packs/application.js
// Support component names relative to this directory:
var componentRequireContext = require.context("components", true);
var ReactRailsUJS = require("react_ujs");
ReactRailsUJS.useContext(componentRequireContext);
my app/javascript/packs/server_rendering.js
// By default, this pack is loaded for server-side rendering.
// It must expose react_ujs as `ReactRailsUJS` and prepare a require context.
var componentRequireContext = require.context("components", true);
var ReactRailsUJS = require("react_ujs");
ReactRailsUJS.useContext(componentRequireContext);
any solution? Thank You
Anything you want available when compiling in production mode needs to be in dependencies. Move #babel/preset-env out of devDependencies into dependencies in package.json. You can also delete babel-preset-env since that is redundant.

`babel-loader` dependency error when `rake assets:precompile` in production

I've inherited a Rails application and I'm trying to get it to build manually in production
The application uses
webpacker-3.5.5 ruby gem to manage JavaScript assets
webpack v3.12.0
sprockets gem to manage traditional CSS / Image assets
As part of the webpacker gem config, it uses babel-loader on JSX/React assets particularly. I'm not quite sure what this does, but I'm guessing it's some sort of pre-processor?
module.exports = {
test: /\.jsx?$/,
exclude: /node_modules/,
use: [{
loader: "babel-loader",
options: {
cacheDirectory: true,
// Use .babelrc - not webpack config JS - to define all options
babelrc: true
}
}]
}
When I try to run rake assets:precompile on the production server, it errors on the step where it tries to build assets with webpack
> rake assets:precompile
yarn install v1.17.3
warning package.json: No license field
warning delly#1.0.0: No license field
[1/4] Resolving packages...
success Already up-to-date.
Done in 1.18s.
Webpacker is installed 🎉 🍰
Using /app/config/webpacker.yml file for setting up webpack paths
Compiling…
Compilation failed:
Hash: 27785324c8b2ba6004dd
Version: webpack 3.12.0
Time: 119ms
Asset Size Chunks Chunk Names
manifest.json 2 bytes [emitted]
ERROR in Entry module not found: Error: Can't resolve 'babel-loader' in '/app'
ERROR in Entry module not found: Error: Can't resolve 'babel-loader' in '/app'
This does not happen in development locally, only production.
Any idea why this would be erroring? Is babel-loader required in production or can I remove it from production entirely?
Here is my package.json that defines installation of the package:
{
"name": "delly",
"version": "1.0.0",
"scripts": {
"test": "node_modules/.bin/jest --no-cache --config spec/javascript/jest.config.js",
"test:debug": "node --inspect-brk node_modules/.bin/jest --no-cache --config spec/javascript/jest.config.js --colors --verbose"
},
"devDependencies": {
"#babel/cli": "^7.4.4",
"#babel/core": "^7.4.5",
"#babel/plugin-proposal-class-properties": "^7.4.4",
"#babel/plugin-proposal-object-rest-spread": "^7.4.4",
"#babel/plugin-syntax-dynamic-import": "^7.2.0",
"#babel/plugin-transform-modules-commonjs": "^7.4.4",
"#babel/preset-env": "^7.4.5",
"#babel/preset-react": "^7.0.0",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^24.8.0",
"babel-loader": "^8.0.6",
"babel-plugin-module-resolver": "^3.2.0",
"eslint": "^4.6.1",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.6.1",
"i18n-js": "^3.2.2",
"jest": "^24.8.0",
"jest-dom": "^3.4.0",
"js-yaml": "^3.13.1",
"react-testing-library": "^7.0.1",
"stylelint": "^9.3.0",
"stylelint-config-rational-order": "^0.0.2",
"webpack-dev-server": "2.11.2"
},
"dependencies": {
"#rails/webpacker": "^3.5.5",
"axios": "^0.19.0",
"core-js": "3",
"html-react-parser": "^0.4.6",
"jquery": "^3.3.1",
"jquery-ujs": "^1.2.2",
"prop-types": "^15.6.1",
"rails-erb-loader": "^5.4.1",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"react-on-rails": "^11.3.0",
"react-toggle-switch": "^3.0.4",
"react-transition-group": "1.x",
"react_ujs": "^2.4.4"
}
}
a
When you run rake assets:precompile in production mode, it also runs webpack using production mode, in this case, only packages set in dependencies are loaded, if you review packages.json, babel-loader is set in devDependencies.\
The solution? move babel-loader to dependencies

Resources