This is not the same as this since his problemended being src spelled wrong, and none of the other solutions worked for me.
I am trying to create some cloud function for my firebase app and got the following error just after setup.
The error
node:internal/modules/cjs/loader:1063
throw err;
^
Error: Cannot find module 'C:\Users\Documents\firebase-functions\lib\bin\firebase-functions.js'
at Module._resolveFilename (node:internal/modules/cjs/loader:1060:15)
at Module._load (node:internal/modules/cjs/loader:905:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
at node:internal/main/run_main_module:23:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
package.json
{
"name": "functions",
"scripts": {
"lint": "eslint --ext .js,.ts .",
"build": "tsc",
"build:watch": "tsc --watch",
"serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "18"
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "^11.5.0",
"firebase-functions": "^4.2.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.12.0",
"@typescript-eslint/parser": "^5.12.0",
"eslint": "^8.9.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-import": "^2.25.4",
"firebase-functions-test": "^3.0.0",
"typescript": "^4.9.0"
},
"private": true
}
More info
I am using typescript, I only changed some of the eslint config since the default setup comes with errors regarding that, and I am using the latest version of node installed globaly.
What I have done
- Used nvm to switch versions (tried version 14 - 19), while changing the version here:
"engines": {
"node": "18"
},
- Initialized the app with diffrent versions
- Uninstalled nvm and installed node 18 alone
- Used diffrent versions of firebase-tools
- Initialized app without eslint
- Tried firebase emulators:start with/without code in index.ts
- Made sure I am in the 'functions' directory
- ran tsc
- ran npm install multiple times
- Deleted node_modules and lock file and re-ran npm install (continiously)
- Changed:
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
to
"predeploy": [
"npm --prefix functions run build"
]
I have succesfuly created one functioning project folder using js instead of ts, without eslint, and I cannot replicate it. I am using the same (latest) node version with node: "18" in package.json.
What I expect
A succesful build when runnig npm run build
or firebase emulators:start