I am working on a Firebase server-side code for sending push notifications. To make the code clean, I decided to move some functions to another class which I created and called notificationFunctions.js.
When I do const notificationFunctions = require('notificationFunctions'); at the top of my index.js and call the function from within my sendNotification function, I get an error when deploying my project to the cloud:
⚠ functions[sendNotifications]: Deployment error.
Build failed: exit status 1
npm ERR! Linux 4.4.0-108-generic
npm ERR! argv "/nodejs/bin/node" "/nodejs/bin/npm" "--global-style" "--production" "--fetch-retries=5" "--fetch-retry-factor=2" "--fetch-retry-mintimeout=1000" "install" "/workspace"
npm ERR! node v6.11.5
npm ERR! npm v3.10.10
npm ERR! code E404
npm ERR! 404 Registry returned 404 for GET on https://registry.npmjs.org/notificationFunctions
npm ERR! 404
npm ERR! 404 'notificationFunctions' is not in the npm registry.
npm ERR! 404 Your package name is not valid, because
npm ERR! 404 1. name can no longer contain capital letters
npm ERR! 404 It was specified as a dependency of 'functions'
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
npm ERR! Please include the following file with any support request:
npm ERR! /workspace/npm-debug.log
Functions deploy had errors. To continue deploying other features (such as database), run:
firebase deploy --except functions
I have also added "notificationFunctions": "1.0.0" in my package.json and moved the custom function to node_modules folder.
What is the right way of adding a custom class to Firebase NodeJS?
Edit:
When I follow Doug Stevenson's advise and I remove the custom class from my package.json, and move the class to the same directory as index.js, I still keep getting an error:
i deploying functions
i functions: ensuring necessary APIs are enabled...
✔ functions: all necessary APIs are enabled
i functions: preparing functions directory for uploading...
Error: Error parsing triggers: Cannot find module 'notificationFunctions'
Try running "npm install" in your functions directory before deploying.
Edit 2
Ok. I figured I have to change the way I import my class to require('./notificationFunctions') and this removes all errors when deploying the project.
Once I run the code on the cloud however, I get this error: FIREBASE WARNING: Exception was thrown by user callback. TypeError: notificationFunctions.getNotificationPayload is not a function
The way I call the function from my code is: const payload = notificationFunctions.getNotificationPayload(userLanguage, senderName, groupName, messageContent, messageType);
If you add code to your project in the functions folder, you don't need to make any changes to your package.json dependencies. npm dependencies are only required for modules that are published to the NPM registry.
What your build is doing now is looking for a node module called "notificationFunctions" on NPM, and that obviously doesn't exist there. You should just put your module code along with all the other code under functions and require() it directly from there.
Also, bear in mind that node_modules is not deployed with your code. Cloud Functions will fetch all the npm dependencies on the server side and make them available to your code.
Related
The monorepo I am using is a complete Nextjs app in itself.
For the use case I am looking for,
some_previous_project
is a package defined in package.json installed from git. I only need to import the utility functions and components from it. The project was done in es6 so transpiling is necessary for the execution. I need every component or function imported from this package to be transpiled.
The configuration I am currently using is:
const withTM = require('next-transpile-modules')(['some_previous_project']);
const withPlugins = require('next-compose-plugins');
const nextConfig = {
target: 'serverless',
webpack(config) {
return config;
},
};
module.exports = withPlugins([withTM], nextConfig);
This throws the following error:
C:\Users\prajwaldankit\Desktop\truemark\ecom-078\current_project>npm run dev
> trendline-frontend#0.1.0 dev C:\Users\prajwaldankit\Desktop\truemark\ecom-078\current_project
> next dev
Error: next-transpile-modules - an unexpected error happened when trying to resolve "some_previous_project"
Error: Can't resolve 'some_previous_project' in 'C:\Users\prajwaldankit\Desktop\truemark\ecom-078\current_project'
at getPackageRootDirectory (C:\Users\prajwaldankit\Desktop\truemark\ecom-078\current_project\node_modules\next-transpile-modules\src\next-transpile-modules.js:70:11)
at Array.map (<anonymous>)
at generateModulesPaths (C:\Users\prajwaldankit\Desktop\truemark\ecom-078\current_project\node_modules\next-transpile-modules\src\next-transpile-modules.js:81:33)
at withTM (C:\Users\prajwaldankit\Desktop\truemark\ecom-078\current_project\node_modules\next-transpile-modules\src\next-transpile-modules.js:110:26)
at C:\Users\prajwaldankit\Desktop\truemark\ecom-078\current_project\node_modules\next-compose-plugins\lib\compose.js:100:23
at Array.forEach (<anonymous>)
at composePlugins (C:\Users\prajwaldankit\Desktop\truemark\ecom-078\current_project\node_modules\next-compose-plugins\lib\compose.js:77:11)
at C:\Users\prajwaldankit\Desktop\truemark\ecom-078\current_project\node_modules\next-compose-plugins\lib\index.js:22:38
at normalizeConfig (C:\Users\prajwaldankit\Desktop\truemark\ecom-078\current_project\node_modules\next\dist\next-server\server\config.js:7:494)
at loadConfig (C:\Users\prajwaldankit\Desktop\truemark\ecom-078\current_project\node_modules\next\dist\next-server\server\config.js:8:131)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! current_project#0.1.0 dev: `next dev`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the current_project#0.1.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\prajwaldankit\AppData\Roaming\npm-cache\_logs\2020-12-11T06_38_48_407Z-debug.log
Your monorepo is wrongly set up as it states in the error message. If you want to use next-transpile-modules with NextJS and monorepo you need to make sure that your monorepo is correctly set up, for which you can use Lerna if you're using npm or yarn workspaces if you're using yarn.
Once that's correctly set up, you need to point your package "main" to be the source of your some_previous_project in order for TM to pick them up. An alternative is to set it up so that your other project creates an ES5 build each time it's changed, but that can quickly occupy your CPU. Another option is to create a Webpack alias in your Next project's config for each of your monorepo modules to resolve imports to src (or wherever your source is), which is what I have done for a project where Next is the development environment and packages have to be able to deploy separately too.
To solve your problem however you first need to make it so that your package resolves, which means you need to set up your monorepo correctly.
I created a todolist that is working properly in localhost.
Iam trying to deploy it on github, when I run '$ npm run deploy' in command propmt it showing error p
Added homepage, predeploy, deploy properties to package.json
installed gh-pages --save-dev
Please help I am a beginner
This is the command prompt error.
C:\Users\Syed\Desktop\project\todolist>npm run deploy
> todolist#0.1.0 predeploy C:\Users\Syed\Desktop\project\todolist
> npm run build
> todolist#0.1.0 build C:\Users\Syed\Desktop\project\todolist
> react-scripts build
Creating an optimized production build...
Compiled with warnings.
./src/App.js
Line 2:8: 'logo' is defined but never used no-unused-vars
Line 52:20: Expected to return a value in arrow function array-callback-return
Search for the keywords to learn more about each warning.
To ignore, add // eslint-disable-next-line to the line before.
File sizes after gzip:
55.54 KB build\static\js\2.0512a152.chunk.js
1.19 KB build\static\js\main.1e3fd05a.chunk.js
785 B build\static\js\runtime-main.ce724f51.js
657 B build\static\css\main.362672fb.chunk.css
The project was built assuming it is hosted at /To-Do-List/.
You can control this with the homepage field in your package.json.
The build folder is ready to be deployed.
Find out more about deployment here:
bit.ly/CRA-deploy
> todolist#0.1.0 deploy C:\Users\Syed\Desktop\project\todolist
> gh-pages -d build
fatal: A branch named 'gh-pages' already exists.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! todolist#0.1.0 deploy: `gh-pages -d build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the todolist#0.1.0 deploy script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Syed\AppData\Roaming\npm-cache\_logs\2020-07-02T01_49_57_997Z-debug.log
Please check this quickstart guide
You will need to set up the GitHub pages homepage link on your GitHub repository settings page first.
Then check the source as well.
Then save. That should work.
To solve the issue with
fatal: A branch named 'gh-pages' already exists.
remove the 'gh-pages/' folder at node_modeules/.cache/
This worked for me
I am not professional in react and these tools.
But error log states that you already have a branch named "gh-pages" check your github repository and delete it.
You would find this if you've searched a little bit.
Delete node_modules/gh-pages/.cache and try again.
Linux / macOS / Git bash: rm -rf node_modules/gh-pages/.cache
I am trying to use following bit.dev community reusable component ( semantic-ui-react table ) in my application, link I am trying is as below:
https://bit.dev/semantic-org/semantic-ui-react/table?example=5c920bc8c634f0001a931879
We can use same in application using npm i #bit/semantic-org.semantic-ui-react.table
But whenever I do that following error ( Note : For other #bit modules also we are getting same issue ) :
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/#bit%2fsemantic-org.semantic-ui-react.table - Not found
npm ERR! 404
npm ERR! 404 '#bit/semantic-org.semantic-ui-react.table#latest' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
I think you get this error because you have not configured #bit as a registry.
https://docs.bit.dev/docs/installing-components.html
I also faced same problem for pulling a component from my private collection. In the official YouTube video registry configuration step is missing.
To install components with npm or yarn we first need to configure #bit as a scoped registry. Bit does it by default as part of the bit login process.
To configure the registry manually, use the npm config command. (For pulling public components)
npm config set #bit:registry https://node.bit.dev
To install private components use npm login. Use your Bit credentials to login.
npm login --registry=https://node.bit.dev --scope=#bit
(This will prompt for user login via CLI.)
I just want to create a new React app with:
npx start-react-app my_new_app
But I get this error:
npm ERR! code E404
npm ERR! 404 Not Found: crate-react-app#latest
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/hugovillalobos/.npm/_logs/2018-12-17T21_01_13_727Z-debug.log
Install for crate-react-app#latest failed with code 1
I attempted to do it with sudo privileges, but I just got the same error.
EDIT
I found that the error rises because I created the React app and then removed the whole directory in order to start over. Now, when I try to use the same directory name in the same parent directory, I get this error. When I use another directory, everything works with no problem.
I guess there should be some global React configurations that must be cleared besides just erasing the directory.
You can try to follow steps here https://www.valentinog.com/blog/react-webpack-babel/ It should work.
npm i react react-dom --save-dev
I am developing a schematics collection for #angular/cli. I would like to test locally how it is working.
Is it possible to test ng-add CLI feature locally?
After linking project with npm link and running ng add myFeature, #angular/cli tries to download the desired library from the npm, what causes following issue:
npm ERR! code E404
npm ERR! 404 Not Found: myLibrary#latest
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/mtreder/.npm/_logs/2018-05-09T10_13_58_291Z-debug.log
Package install failed, see above.
Package install failed, see above.
Can I somehow mock, npm registry to my local environment?
You can use verdaccio to mock a local registry and publish your own stuff and resolve the remaining dependencies from npmjs.
https://www.verdaccio.org/
Here some answer might helpful for you.
Private and Public NPM Package Install in Single Command
I'm not sure whether this 100% answer your question, but, I hope it helps.