Deploying on AWS Amplify - amazon-web-services

I have a web application which I want to deploy on AWS amplify.
I am very new to this, following the procedure, I always get a build error (command ng build not found)
My app builds perfectly on local machine, and all the files are transferred to GIT repository.
The app uses AppSync and Aurora as well.
Any help would be much appreciated.
{
"name": "new-impact",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "[ -f src/aws-exports.js ] && mv src/aws-exports.js src/aws-exports.ts || ng serve; ng serve",
"build": "[ -f src/aws-exports.js ] && mv src/aws-exports.js src/aws-exports.ts || node ./node_modules/#angular/cli/bin/ng build --prod; node ./node_modules/#angular/cli/bin/ng build --prod",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"#angular/animations": "~9.0.3",
"#angular/common": "~9.0.3",
"#angular/compiler": "~9.0.3",
"#angular/core": "~9.0.3",
"#angular/forms": "~9.0.3",
"#angular/localize": "^9.1.0",
"#angular/platform-browser": "~9.0.3",
"#angular/platform-browser-dynamic": "~9.0.3",
"#angular/router": "~9.0.3",
"#ng-bootstrap/ng-bootstrap": "^6.0.2",
"apollo-angular": "^1.8.0",
"apollo-angular-link-http": "^1.9.0",
"apollo-boost": "^0.4.7",
"apollo-cache-inmemory": "^1.6.0",
"apollo-client": "^2.6.8",
"apollo-env": "^0.6.2",
"apollo-link": "^1.2.13",
"aws-amplify": "^2.3.0",
"aws-appsync": "^3.0.2",
"d3-scale": "^3.2.1",
"d3plus": "^2.0.0-alpha.25",
"graphql": "^14.6.0",
"graphql-tag": "^2.10.3",
"ngx-chips": "^2.1.0",
"ngx-pagination": "^5.0.0",
"rxjs": "~6.5.4",
"tslib": "^1.10.0",
"zone.js": "~0.10.2"
},
"devDependencies": {
"#angular-devkit/build-angular": "~0.900.4",
"#angular/cli": "~9.0.4",
"#angular/compiler-cli": "~9.0.3",
"#angular/language-service": "~9.0.3",
"#types/jasmine": "~3.5.0",
"#types/jasminewd2": "~2.0.3",
"#types/node": "^12.11.1",
"codelyzer": "^5.1.2",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~2.1.0",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.2",
"protractor": "~5.4.3",
"ts-node": "~8.3.0",
"tslint": "~5.18.0",
"typescript": "~3.7.5"
}
}
// Build error
13 verbose stack at ChildProcess.emit (events.js:198:13)
13 verbose stack at maybeClose (internal/child_process.js:982:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid new-impact#0.0.0
15 verbose cwd /codebuild/output/src651454953/src/test
16 verbose Linux 4.14.165-103.209.amzn1.x86_64
17 verbose argv "/root/.nvm/versions/node/v10.16.0/bin/node" "/root/.nvm/versions/node/v10.16.0/bin/npm" "run" "build"
18 verbose node v10.16.0
19 verbose npm v6.9.0
20 error code ELIFECYCLE
21 error errno 1
22 error new-impact#0.0.0 build: `[ -f src/aws-exports.js ] && mv src/aws-exports.js src/aws-exports.ts || node ./node_modules/#angular/cli/bin/ng build --prod; node ./node_modules/#angular/cli/bin/ng build --prod`
22 error Exit status 1
23 error Failed at the new-impact#0.0.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
2020-05-04T21:58:06.455Z [ERROR]: !!! Build failed
2020-05-04T21:58:06.507Z [ERROR]: !!! Non-Zero Exit Code detected
2020-05-04T21:58:06.507Z [INFO]: # Starting environment caching...
2020-05-04T21:58:06.507Z [INFO]: # Environment caching completed
Terminating logging...

There can be a number of reasons, but it might be this one:
(if not, could you update your question with your package.json file and the build error from the amplify console?)
The amplify console will run node run build when it starts the build and not the angular cli, ng build.
You need to update the build script in your package.json file so that node run build will run ng build:
...
"scripts" : {
...
"start": "[ -f src/aws-exports.js ] && mv src/aws-exports.js src/aws-exports.ts || ng serve; ng serve",
"build": "[ -f src/aws-exports.js ] && mv src/aws-exports.js src/aws-exports.ts || node ./node_modules/#angular/cli/bin/ng build --prod; node ./node_modules/#angular/cli/bin/ng build --prod",
...
}
This include automatic renaming of your aws-exports file from aws-exports.js to aws-exports.ts if you have forgotten to rename it manually.
The line node ./node_modules/#angular/cli/bin/ng build --prod; is the line needed to make aws amplify console to build your angular app correctly.

I came across the same problem of having build issues on AWS Amplify. I found out I had dependencies with different versions in package-lock-json. I tried running
npm ci and it fixed the problem.

Related

Nodemon is not working: How can i resolve it?

I have installed nodemon globally(npm i -g nodemon), I get the message that nodemon is properly installed:
My package.json:
{
"name": "backend",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.18.1",
"nodemon": "^2.0.19"
}
}
When i run it i get the message :
nodemon' n’est pas reconnu en tant que commande interne
ou externe, un programme exécutable ou un fichier de commandes.
To check that is it really installed on you system use nodemon -h command or with sudo nodemon -h. If it only responded when tried with sudo, that means you should run it with sudo from now on.
You can use it in a different way without the need for such a mess. First remove it by using npm uninstall -g nodemon command.
It is recommended to use Nodemon only for development purposes. So that means it is dev tool and you don't need it install as main dependencies.
So, you can basically install it as dev dependencies using this command: npm install --save-dev nodemon.
Then change the scripts (package.json):
"scripts": {
"start": "nodemon server.js"
},
Now when you just npm start the script will work.

Build script doesn't copy all files with babel

I want to create, for the first time, a npm package from a react component. I'm following this tutorial here
But when I try the build script, I have some error. Because I'm working on windows/vscode powershell terminal, I changed rm-rf to del/s/q/f and installed cross-env.
"build": "del/s/q/f dist && cross-env NODE_ENV=production babel src/lib --out-dir dist --copy-files"
Now it partially worked but many files are missing in dist folder.
Here is the error msg
ReferenceError: [BABEL] src\lib\components\DatePicker.jsx: Unknown option: C:\Users\romai\Workspace\Openclassrooms\Frontend\HRNet\hrnet_react_datepicker\node_modules\babel-preset-react-app\index.js.overrides. Check out http://babeljs.io/docs/usage/options/ for more information about options.
A common cause of this error is the presence of a configuration options object without the corresponding preset name. Example:
Invalid:
`{ presets: [{option: value}] }`
Valid:
`{ presets: [['presetName', {option: value}]] }`
For more detailed information on preset configuration, please see https://babeljs.io/docs/en/plugins#pluginpresets-options. (While processing preset: "C:\\Users\\romai\\Workspace\\Openclassrooms\\Frontend\\HRNet\\hrnet_react_datepicker\\node_modules\\babel-preset-react-app\\index.js")
at Logger.error (C:\Users\romai\Workspace\Openclassrooms\Frontend\HRNet\hrnet_react_datepicker\node_modules\babel-core\lib\transformation\file\logger.js:41:11)
at OptionManager.mergeOptions (C:\Users\romai\Workspace\Openclassrooms\Frontend\HRNet\hrnet_react_datepicker\node_modules\babel-core\lib\transformation\file\options\option-manager.js:226:20)
at C:\Users\romai\Workspace\Openclassrooms\Frontend\HRNet\hrnet_react_datepicker\node_modules\babel-core\lib\transformation\file\options\option-manager.js:265:14
at C:\Users\romai\Workspace\Openclassrooms\Frontend\HRNet\hrnet_react_datepicker\node_modules\babel-core\lib\transformation\file\options\option-manager.js:323:22
at Array.map (<anonymous>)
at OptionManager.resolvePresets (C:\Users\romai\Workspace\Openclassrooms\Frontend\HRNet\hrnet_react_datepicker\node_modules\babel-core\lib\transformation\file\options\option-manager.js:275:20)
at OptionManager.mergePresets (C:\Users\romai\Workspace\Openclassrooms\Frontend\HRNet\hrnet_react_datepicker\node_modules\babel-core\lib\transformation\file\options\option-manager.js:264:10)
at OptionManager.mergeOptions (C:\Users\romai\Workspace\Openclassrooms\Frontend\HRNet\hrnet_react_datepicker\node_modules\babel-core\lib\transformation\file\options\option-manager.js:249:14)
at OptionManager.init (C:\Users\romai\Workspace\Openclassrooms\Frontend\HRNet\hrnet_react_datepicker\node_modules\babel-core\lib\transformation\file\options\option-manager.js:368:12)
at File.initOptions (C:\Users\romai\Workspace\Openclassrooms\Frontend\HRNet\hrnet_react_datepicker\node_modules\babel-core\lib\transformation\file\index.js:212:65)
The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command npm run build" terminated with exit code: 1.
Here is the src structure
Here is my current builded dist folder
.babelrc
{
"presets": [
["react-app", { "absoluteRuntime": false }]
]
}
Actual package.json
{
"name": "xxx",
"version": "1.0.0",
"main": "dist/index.js",
"module": "dist/index.js",
"files": [
"dist",
"README.md"
],
"private": false,
"description": "datepicker component for personnal openclassrooms hrnet project",
"repository": {
"type": "git",
"url": "git+https://github.com/xxx"
},
"scripts": {
"start": "react-scripts start",
"build": "del/s/q/f dist && cross-env NODE_ENV=production babel src/lib --out-dir dist --copy-files",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-react-app": "^10.0.1",
"cross-env": "^7.0.3",
"sass": "^1.49.9"
},
"dependencies": {
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "5.0.0"
}
}
Thanks in advance
I got the same error and decided to debug. This debugging lead me to create.js in node_modules/babel-preset-react-app, which contains "overrides". This is the key that is being rejected. Commenting that part out gives the following error:
Error: Requires Babel "^7.0.0-0", but was loaded with "6.26.3". If you are sure you have a compatible version of #babel/core, it is likely that something in your build process is loading the wrong version. Inspect the stack trace of this error to look for the first entry that doesn't mention "#babel/core" or "babel-core" to see what is calling Babel. (While processing preset: "blabla/frontend/shared/node_modules/babel-preset-react-app/index.js")
This lead me to brave-search "babel-cli 7", which gives https://babeljs.io/docs/en/babel-cli.
A note here states Note: Please install #babel/cli and #babel/core first before npx babel, otherwise npx will install out-of-dated babel 6.x. Other than npx, you can also drop it inside of an npm run script or you may instead execute with the relative path instead. ./node_modules/.bin/babel
Notice it states #babel/cli. Looking at package-lock.json, I see babel-cli. Removing that one and installing #babel/cli gave me version 7.
TLDR: uninstall babel-cli, install #babel/cli.

No files matching the pattern were found with STYLELINT

I just installed STYLELINT and I'm following the documentation, but I encountered the following problem:
$ npx stylelint --config ./stylelintrc './**/*.tsx'
Error: No files matching the pattern "'./src/**/*.tsx'" were found.
at standalone (C:\Users\thiag\OneDrive\Documentos\PROJETOS\sugar\node_modules\stylelint\lib\standalone.js:273:43)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
error Command failed with exit code 1.
Here's my hierarchy:
Here's my code .stylelintrc:
{
"processors": ["stylelint-processor-styled-components"],
"extends": ["stylelint-config-recommended", "stylelint-config-styled-components"],
"customSyntax": "postcss-scss",
"rules": { // BAR }
}
Package code:
{
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject",
"stylelint:check": "stylelint-config-prettier-check",
"stylelint:css": "npx stylelint './**/*.{tsx, ts}'",
"prepare": "husky install"
},
"dependencies": {
"expo": "~44.0.0",
"expo-status-bar": "~1.2.0",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-native": "0.64.3",
"react-native-web": "0.17.1",
"styled-components": "^5.3.5"
},
"devDependencies": {
"#babel/core": "^7.12.9",
"#stylelint/postcss-css-in-js": "^0.37.2",
"#types/react": "~17.0.21",
"#types/react-native": "~0.64.12",
"#types/styled-components": "^5.1.25",
"#types/styled-components-react-native": "^5.1.3",
"#typescript-eslint/eslint-plugin": "^5.19.0",
"#typescript-eslint/parser": "^5.19.0",
"eslint": "8.2.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "2.25.3",
"eslint-plugin-jsx-a11y": "6.5.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "7.28.0",
"eslint-plugin-react-hooks": "4.3.0",
"husky": "^7.0.4",
"lint-staged": "^12.3.7",
"postcss-scss": "^4.0.3",
"postcss-syntax": "^0.36.2",
"prettier": "^2.6.2",
"stylelint": "^14.6.1",
"stylelint-config-prettier": "^9.0.3",
"stylelint-config-recommended": "^7.0.0",
"stylelint-config-styled-components": "^0.1.1",
"stylelint-processor-styled-components": "^1.10.0",
"typescript": "~4.3.5"
}
}
What is happening here? I've tried everything with these paths and nothing works. I'm using it in a project with EXPO + STYLED-COMPONENTS.
Stylelint is throwing the following error because there is no src folder in your hierarchy and therefore no .tsx files to lint:
Error: No files matching the pattern "'./src/**/*.tsx'" were found.
The error will go away once you create a .tsx file in a src folder. Alternatively, you can use the --allow-empty-input flag, like so:
npx stylelint './**/*.tsx' --allow-empty-input
Additionally, you don't need the --config flag as Stylelint will find a .stylelintrc file automatically.

Firebase Functions TypeScript unit testing devDependencies

Following the guideline here: https://firebase.google.com/docs/functions/unit-testing
I'm trying to write unit tests to my TS functions.
here's my package.json:
{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log",
"test": "mocha --reporter spec"
},
"main": "lib/index.js",
"dependencies": {
"#types/algoliasearch": "^3.27.0",
"#types/axios": "^0.14.0",
"#types/nodemailer": "^4.6.0",
"#types/stripe": "^5.0.11",
"algoliasearch": "^3.27.1",
"axios": "^0.18.0",
"firebase-admin": "~5.12.0",
"firebase-functions": "^1.0.3",
"nodemailer": "^4.6.4",
"stripe": "^5.8.0",
"webpack": "^4.7.0"
},
"devDependencies": {
"#types/node": "^9.6.6",
"firebase-functions-test": "^0.1.2",
"mocha": "^5.2.0",
"ts-loader": "^4.2.0",
"tslint": "^5.8.0",
"typescript": "^2.8.3",
"webpack-cli": "^2.1.2",
"webpack-node-externals": "^1.7.2"
},
"private": true
}
and I have 1 problem and 1 question.
problem:
I can't import the firebase-functions-test
in my index.test.ts file.
it is looking for it in dependencies only and not in devDependencies...
(adding it inside dependencies solve it).
question:
Can I move all the #types to devDependencies?
Thanks.
If I am right you probably get error something like
Module 'firebase-functions-test' is not listed as dependency in package.json
In fact this is because you have enabled tslint rule no-implicit-dependencies. You can disable it and then you will not get error when importing devDependencies in your unit test.
You can change set tslint to consider dev,
{
...
"rules": {
"no-implicit-dependencies": [true, "dev"],
...
}
see https://github.com/houndci/hound/issues/1522#issuecomment-415760094

Illegal Operation on a Directory with Unknown Broccoli Plugin

Output from ember version --verbose && npm --version:
ember-cli: 2.12.1
http_parser: 2.7.0
node: 6.10.2
v8: 5.1.281.98
uv: 1.9.1
zlib: 1.2.11
ares: 1.10.1-DEV
icu: 58.2
modules: 48
openssl: 1.0.2k
os: darwin x64
3.10.10
When I try ember s I have the following error,
Livereload server on http://localhost:49153
Serving on http://localhost:4200/
The Broccoli Plugin: [object Object] failed with:
Error: EISDIR: illegal operation on a directory, read
at Error (native)
at Object.fs.readSync (fs.js:732:19)
at tryReadSync (fs.js:487:20)
at Object.fs.readFileSync (fs.js:535:19)
at /Users/li-xinyang/Desktop/XX_MemoCycle_Firebase/node_modules/broccoli-flatiron/index.js:33:16
at Array.forEach (native)
at readDirectory (/Users/li-xinyang/Desktop/XX_MemoCycle_Firebase/node_modules/broccoli-flatiron/index.js:28:31)
at /Users/li-xinyang/Desktop/XX_MemoCycle_Firebase/node_modules/broccoli-flatiron/index.js:21:15
at tryCatch (/Users/li-xinyang/Desktop/XX_MemoCycle_Firebase/node_modules/rsvp/dist/rsvp.js:539:12)
at invokeCallback (/Users/li-xinyang/Desktop/XX_MemoCycle_Firebase/node_modules/rsvp/dist/rsvp.js:554:13)
The broccoli plugin was instantiated at:
undefined
Below is a list of devDependencies,
package.json File
{
"name": "memo-cycle",
"version": "0.0.0",
"description": "A study tool for serious learner",
"license": "MIT",
"author": "",
"directories": {
"doc": "doc",
"test": "tests"
},
"repository": "",
"scripts": {
"build": "ember build",
"start": "ember server",
"test": "ember test"
},
"devDependencies": {
"broccoli-asset-rev": "^2.4.5",
"ember-ajax": "^2.4.1",
"ember-cli": "2.12.1",
"ember-cli-app-version": "^2.0.0",
"ember-cli-babel": "^5.1.7",
"ember-cli-dependency-checker": "^1.3.0",
"ember-cli-eslint": "^3.0.0",
"ember-cli-gravatar": "^3.8.1",
"ember-cli-htmlbars": "^1.1.1",
"ember-cli-htmlbars-inline-precompile": "^0.3.6",
"ember-cli-inject-live-reload": "^1.4.1",
"ember-cli-qunit": "^3.1.0",
"ember-cli-sass": "^6.1.2",
"ember-cli-shims": "^1.0.2",
"ember-cli-sri": "^2.1.0",
"ember-cli-uglify": "^1.2.0",
"ember-export-application-global": "^1.0.5",
"ember-in-viewport": "^2.1.1",
"ember-inline-svg": "^0.1.10",
"ember-load-initializers": "^0.6.0",
"ember-paper": "^1.0.0-alpha.19",
"ember-power-select": "^1.6.1",
"ember-power-select-with-create": "^0.3.1",
"ember-resolver": "^2.0.3",
"ember-route-action-helper": "^2.0.2",
"ember-simple-auth": "^1.2.2",
"ember-source": "~2.12.0",
"loader.js": "^4.2.3"
},
"engines": {
"node": ">= 4"
},
"private": true
}
It was working fine before my last to commit. What I have done in the last two commits are I remove all .DS_Store files in the last commit and added Firebase deploy config files and install cloud function dependencies via Yarn in the last second commit.
What I have tried to resolve the issues, but the issue persists.
1) Delete all node modules via rm -rf node_modules and re-install them npm install (dependencies were installed via Yarn)
2) Remove the project and clone from the origin
3) Revert back to early commit (issue persists even I revert back to the initial commit and re-install all the dependencies of course)
4) Restart Mac 😅
5) Update .ember-cli file and re-run ember init setup process
The issues is caused by
That plugin looks like it was built for an older version of broccoli, but the basic problem seems that its write function doesn't handle symlinks to directories.
See this GitHub issue for more details
https://github.com/ember-cli/ember-cli/issues/6981