Can't for the life of me figure out why my app suddenly won't start. I keep getting this error:
Unable to resolve module fs from
node_modules\firebase-admin\lib\firebase-namespace.js: fs could not
be found within the project.
If you are sure the module exists, try these steps:
Clear watchman watches: watchman watch-del-all
Delete node_modules and run yarn install
Reset Metro's cache: yarn start --reset-cache
Remove the cache: rm -rf /tmp/metro-*
whenever I run expo start in the root folder. I've even tried expo start -c to reset the cache.
I've also tried removing node_modules and npm installing it back for both the {myapp}/functions/node_modules and {myapp}/node_modules.
I've tried updating firebase-admin and all dependencies.
It's weird because my app was working a couple days ago and this came out of the blue. I've never had to install fs before.
Anyone got any idea what's going on here? It feels like a simple environment fix, but I'm not sure.
My app dependencies if it helps:
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject",
"test": "jest"
},
"dependencies": {
"#react-native-async-storage/async-storage": "^1.13.0",
"#react-native-community/masked-view": "0.1.10",
"algoliasearch": "^4.8.3",
"axios": "^0.21.1",
"buffer": "^6.0.3",
"expo": "^41.0.0",
"expo-font": "~9.1.0",
"expo-image-picker": "~10.1.4",
"expo-linear-gradient": "~9.1.0",
"expo-notifications": "~0.11.6",
"expo-status-bar": "~1.0.4",
"expo-web-browser": "~9.1.0",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-41.0.0.tar.gz",
"react-native-elements": "^3.0.0-alpha.1",
"react-native-gesture-handler": "~1.10.2",
"react-native-keyboard-aware-scroll-view": "^0.9.3",
"react-native-linear-gradient": "^2.5.6",
"react-native-paper": "^4.7.0",
"react-native-reanimated": "^1.13.3",
"react-native-screens": "^2.10.1",
"react-native-snap-carousel": "^3.9.1",
"react-native-svg": "12.1.0",
"react-native-svg-transformer": "^0.14.3",
"react-native-vector-icons": "^7.1.0",
"react-navigation": "^4.4.3",
"react-navigation-drawer": "^2.6.0",
"react-navigation-header-buttons": "^6.3.1",
"react-navigation-stack": "^2.9.0",
"react-navigation-tabs": "^2.10.1",
"react-redux": "^7.2.2",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0"
},
"devDependencies": {
"firebase": "8.2.3",
"jest": "^26.6.3",
"jest-expo": "^41.0.0",
"react-test-renderer": "^17.0.2"
},
"private": true,
"jest": {
"preset": "jest-expo",
"transformIgnorePatterns": [
"./node_modules/(?!(react-navigation-header-buttons|react-native|react-native-gesture-handler|#expo)|expo-font|#unimodules|expo-asset|expo-constants|expo-file-system|expo-web-browser|react-navigation|react-navigation-stack|unimodules-permissions-interface|expo-permissions|expo-image-picker|expo-linear-gradient/)"
],
"setupFiles": [
"./node_modules/react-native-gesture-handler/jestSetup.js"
],
"verbose": true,
"updateSnapshot": true
}
}
and .babelrc:
{
"presets": [
"babel-preset-expo"
]
}
and firebase functions dependencies:
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "12"
},
"main": "index.js",
"dependencies": {
"algoliasearch": "^4.8.3",
"axios": "^0.21.0",
"cloudinary": "^1.23.0",
"crypto": "^1.0.1",
"events": "^3.3.0",
"express": "^4.17.1",
"firebase": "^8.7.0",
"firebase-admin": "^9.10.0",
"firebase-functions": "^3.14.1"
},
"devDependencies": {
"firebase-functions-test": "^0.2.0"
},
"private": true
}
firebase-admin is then intialized in my {myapp}/functions/index.js as:
const admin = require("firebase-admin");
admin.initializeApp();
and then used as (for example):
// Called for toggling Tutorial Prompt on ProfileScreen
exports.setTutorialPrompt = functions.https.onRequest(async (req, res) => {
res.set("Access-Control-Allow-Origin", "*");
if (req.method === "OPTIONS") {
// Send response to OPTIONS requests
res.set("Access-Control-Allow-Methods", "GET, POST");
res.set("Access-Control-Allow-Headers", "Content-Type");
res.set("Access-Control-Max-Age", "3600");
res.status(201).send("CORS preflight options set!");
} else {
const db = admin.firestore(); // <--------------------------- here
const { exampleId, ExampletwoId, value, screen } = req.body;
const updatedProfile = {
tutorialPrompt: value,
};
const index = await client.initIndex(ALGOLIA_INDEX_NAME);
index
.partialUpdateObject({
objectID: ExhibitUId,
tutorialPrompt: value,
})
.wait();
db.collection("users").doc(localId).update(updatedProfile);
res.status(201).send(`Successfully toggled tutorialing prompt`);
}
});
I managed to fix it.
It was a random import error within the root app folder. Somehow one of my imports got mixed up, and was trying to call a cloud function instead of a redux-action function.
The wrong import:
import { setTutorialPrompt } from "../../functions/index.js";
The correct import:
import { setTutorialPrompt } from "../../store/actions/user";
Since it was trying to import my functions folder, it gave me the fs error. Similar to what #brentvatne was talking about.
If anyone else runs into this error, I recommend moving your cloud functions folder to your desktop or something, and try running your app without it. That's how I found the right error code.
I found this because I ran into pretty much exactly this same issue.
I discovered that there are (weirdly) two ways you can import firebase-admin into react native projects. I was doing import { firestore } from "firebase-admin" and I needed to be doing import firestore from '#react-native-firebase/firestore'
A pretty easy-to-miss difference, so I thought I’d leave a comment here in case anyone else has this issue.
Related
im trying to create a website using NextJS, prisma and netlify functions and deploy it to netlify.
The Website and nextJS framework work quite well while debugging using netlify dev.
The functions dont work. Trying to get a response from the functions ends in this error:
NestedError: Cannot read from `D:/Eigene Dateien/Github/beatraum/node_modules/.prisma`: EISDIR: illegal operation on a directory, read
at Module.createReadStream (file:///C:/Users/s.blaser/AppData/Roaming/npm/node_modules/netlify-cli/node_modules/cp-file/fs.js:21:9)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at copyFileAsync (file:///C:/Users/s.blaser/AppData/Roaming/npm/node_modules/netlify-cli/node_modules/cp-file/index.js:11:21)
at file:///C:/Users/s.blaser/AppData/Roaming/npm/node_modules/netlify-cli/node_modules/#netlify/zip-it-and-ship-it/node_modules/p-map/index.js:141:20
Caused By: Error: EISDIR: illegal operation on a directory, read {
nested: [Error: EISDIR: illegal operation on a directory, read] {
errno: -4068,
code: 'EISDIR',
syscall: 'read'
},
errno: -4068,
code: 'EISDIR',
syscall: 'read',
name: 'CopyFileError'
}
Node.js v18.12.1
It doesnt matter whether I start with netlify dev or netlify functions:serve - both ends in the same error.
I deployed the application and the functions work :o
So only the local environment seems to be broken.
I think it has something to do with the prisma dependency, but im quite unsure.
This is my netlify.toml:
# example netlify.toml
[build]
command = "npm run build"
functions = "netlify/functions"
publish = ".next"
[[plugins]]
package = "#netlify/plugin-nextjs"
## Uncomment to use this redirect for Single Page Applications like create-react-app.
## Not needed for static site generators.
#[[redirects]]
# from = "/*"
# to = "/index.html"
# status = 200
## (optional) Settings for Netlify Dev
## https://github.com/netlify/cli/blob/main/docs/netlify-dev.md#project-detection
[dev]
framework = "next"
command = "next dev -p 8080" # Command to start your dev server
targetPort = 8080 # Port that the dev server will be listening on
# publish = "dist" # Folder with the static content for _redirect file
## more info on configuring this file: https://docs.netlify.com/configure-builds/file-based-configuration/
This is my package.json:
{
"name": "beatraum",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"export": "next export",
"debug": "netlify dev --inspect"
},
"dependencies": {
"#hapi/iron": "^7.0.0",
"#netlify/functions": "^1.4.0",
"#next/font": "13.1.6",
"#prisma/client": "^4.9.0",
"#types/node": "18.11.18",
"#types/react": "18.0.27",
"#types/react-dom": "18.0.10",
"cookie": "^0.5.0",
"eslint": "8.33.0",
"eslint-config-next": "13.1.6",
"netlify-dev-plugin": "^1.0.28",
"next": "13.1.6",
"passport": "^0.6.0",
"passport-local": "^1.0.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-netlify-forms": "^1.3.3",
"swr": "^2.0.3",
"typescript": "4.9.5",
"uuid": "^9.0.0"
},
"devDependencies": {
"autoprefixer": "^10.4.13",
"netlify-cli": "^12.10.0",
"postcss": "^8.4.21",
"prisma": "^4.9.0",
"tailwindcss": "^3.2.4"
}
}
I asked the same question in the netlify forum but didn't receive any answers.
https://answers.netlify.com/t/netlify-dev-functions-cannot-be-called-in-dev-mode-with-prisma-eisdir/85068
Thank you for your help in advance!
I am very new to Vue and I am trying to set up vue-i18n and continue to get console warnings
You are running the esm-bundler build of vue-i18n. It is recommended to configure your bundler to explicitly replace feature flag globals with boolean literals to get proper tree-shaking in the final bundle.
My process
$npm install vue-i18n#next
$npm i --save-dev #intlify/vue-i18n-loader#next
I have tried adding different things to my vue.config.js file based on various stack overflow answers including
module.exports = {
chainWebpack: config =>
{
config.module
.rule( 'i18n' )
.resourceQuery( /blockType=i18n/ )
.type( 'javascript/auto' )
.use( 'i18n' )
.loader( '#intlify/vue-i18n-loader' )
}
}
and
const webpack = require('webpack');
module.exports = {
configureWebpack:
{
plugins: [
// Define Bundler Build Feature Flags
new webpack.DefinePlugin( {
__VUE_OPTIONS_API__: false,
__VUE_I18N_FULL_INSTALL__: true,
__VUE_I18N_LEGACY_API__: true,
__VUE_I18N_PROD_DEVTOOLS__: false,
__INTLIFY_PROD_DEVTOOLS__: false
} ),
],
}
};
When I use the 1st example vue.config.js the global values all log to the console with the correct values, but I still get the warning.
The only thing that seems to remove the error is modifying the i18n import.
import { createI18n } from 'vue-i18n/index'
However, this seems wrong because it just bypasses the file that generates the warning.
My question boils down too...
How can I configure vue-i18n to work with my vue3 project that uses
npm run serve
in a way that removes the console warning? or What are the exact steps to configure/use/add vue-i18n in my vue3 project.
package.json
{
"name": "octo-train-client",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"#mdi/font": "^6.4.95",
"axios": "^0.24.0",
"core-js": "^3.6.5",
"dotenv-webpack": "^7.0.3",
"form-data": "^4.0.0",
"primeflex": "^2.0.0",
"primeicons": "^4.1.0",
"primevue": "^3.8.2",
"vue": "^3.0.0",
"vue-axios": "^3.4.0",
"vue-i18n": "^9.0.0-rc.4",
"vue-router": "^4.0.0-0",
"vuex": "^4.0.0-0"
},
"devDependencies": {
"#intlify/vue-i18n-loader": "^4.1.0",
"#vue/cli-plugin-babel": "~4.5.0",
"#vue/cli-plugin-eslint": "~4.5.0",
"#vue/cli-plugin-router": "~4.5.0",
"#vue/cli-plugin-vuex": "~4.5.0",
"#vue/cli-service": "~4.5.0",
"#vue/compiler-sfc": "^3.0.0",
"#vue/eslint-config-prettier": "^6.0.0",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-vue": "^7.0.0",
"node-sass": "^4.12.0",
"prettier": "^2.2.1",
"sass-loader": "^8.0.2"
}
}
I faced the same problem, and it seems it is normal IF you are on a dev mode.
https://github.com/intlify/vue-i18n-next/issues/810
You should not see that on a production level
The meaning of this warning message is that you need to specify the flag explicitly in the bundler when you do a production build.
Please refer to the following link for packages provided by vue-i18n for bundlers.
https://vue-i18n.intlify.dev/installation.html#with-a-bundler
One advice to help you out is to use the plugins for each bundler listed in the NOTE section of the above link, and they will configure them properly for you. I recommend that you check them out.
Checkout this issue listed in GitHub forum.
While trying to redeploy a function I now get this error message: Error parsing triggers: Cannot find module 'core-js / fn / reflect'.
Here's my package.json:
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "14"
},
"main": "index.js",
"dependencies": {
"#google-cloud/logging": "^9.1.0",
"#woocommerce/woocommerce-rest-api": "^1.0.1",
"algoliasearch": "^4.8.5",
"cors": "^2.8.5",
"csvtojson": "^2.0.10",
"express": "^4.17.1",
"firebase-admin": "^9.2.0",
"firebase-functions": "^3.14.1",
"mkdirp": "^1.0.4",
"stripe": "^8.137.0"
},
"devDependencies": {
"firebase-functions-test": "^0.2.0"
},
"private": true
}
In index.js i use
const cors = require('cors')({origin: true});
....
exports.StripeEvents = functions.https.onRequest((req, res) => {
cors(req, res, () => {
//// some code that worked great
}
}
I do not use cors-js package at all...
Where does the problem comes from?
Thank you
depending the browser that you are using and the Javascript that you are using in some cases they do not support all the features required by Firebase so you need to at the Polyfills, in this documentation they show you the way to add the Polyfills to your app, the no recommended way to do it is with the core-js library, feel free to do it what you want.
I quick way to solve the error could be go to the directory where your functions live and execute:
solution install core-js#2.6.5
I am using the Vue cli to create a vue app with Firebase as my backend.
A file within my app initializes the Firebase DB by referring to environment variables that are defined in .env files.
.env
FIREBASE_API_KEY=#################################
FIREBASE_AUTH_DOMAIN=#################################
FIREBASE_DB_URL=https://#################################
FIREBASE_PROJECT_ID=#################################
FIREBASE_STORAGE_BUCKET=#################################
FIREBASE_MESSAGING_SENDER_ID=#################################
AUTH_API=https://#################################
.env.development.local and .env.production.local contain the same data.
Within my app I have a file that looks like this:
credentials.js
export default {
config: {
apiKey: process.env.VUE_APP_FIREBASE_API_KEY,
authDomain: process.env.VUE_APP_FIREBASE_AUTH_DOMAIN,
storageBucket: process.env.VUE_APP_FIREBASE_STORAGE_BUCKET,
databaseURL: process.env.VUE_APP_FIREBASE_DB_URL,
projectId: process.env.VUE_APP_FIREBASE_PROJECT_ID,
messagingSenderId: process.env.VUE_APP_FIREBASE_MESSAGING_SENDER_ID
}
}
When I serve the development version of this app using yarn serve, the database is initialized, so the .env variables are obviously read without a problem. However, when I use yarn build and then serve the resulting files in dist, I get an error on the console:
#firebase/database: FIREBASE FATAL ERROR: Can't determine Firebase Database URL. Be sure to include databaseURL option when calling firebase.initializeApp().
Which is basically telling me that the environment variables are not being read in production mode.
Here is my package.json:
{
"name": "web-app",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"#firebase/firestore": "^1.9.3",
"axios": "^0.19.0",
"core-js": "^3.3.2",
"element-ui": "^2.12.0",
"feather-icons": "^4.24.1",
"firebase": "^7.2.3",
"firebase-admin": "^8.9.2",
"firebase-functions": "^3.3.0",
"localforage": "^1.7.3",
"node-ipc": "^9.1.1",
"vue": "^2.6.10",
"vue-feather": "^1.0.0",
"vue-feather-icons": "^5.0.0",
"vue-router": "^3.1.3",
"vue2-animate": "^2.1.3",
"vuedraggable": "^2.23.2",
"vuefire": "^2.2.0",
"vuex": "^3.1.1",
"vuex-persist": "^2.1.1"
},
"devDependencies": {
"#vue/cli-plugin-babel": "^4.0.0",
"#vue/cli-service": "^4.0.0",
"babel-eslint": "^10.0.3",
"eslint": "^5.16.0",
"eslint-plugin-vue": "^5.0.0",
"vue-template-compiler": "^2.6.10"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"rules": {},
"parserOptions": {
"parser": "babel-eslint"
}
},
"postcss": {
"plugins": {
"autoprefixer": {}
}
},
"browserslist": [
"> 1%",
"last 2 versions"
]
}
Can anyone tell me what might be causing this?
You need to prefix your variables with VUE_APP_ in your .env files.
From https://cli.vuejs.org/guide/mode-and-env.html#environment-variables:
Note that only variables that start with VUE_APP_ will be statically embedded into the client bundle with webpack.DefinePlugin.
Describe the bug
I'm struggling to import external packages to use with Detox test files. My specific use case is that a testID is linked to a unique key that I need to pull from a firebase database. I've looked through these threads documenting similar issues, but all the solutions that I've tried have not worked for me (the majority of the responses were from 2018/early 2019)
https://github.com/vuejs/vue-cli/issues/1584
https://github.com/facebook/jest/issues/6933
Is there a current consensus on the best way to import modules into a test.spec.js style e2e file so that Detox can use them in tests?
To Reproduce
[x] I have tested this issue on the latest Detox release and it still reproduces
Steps to reproduce:
1. add import database from '#react-native-firebase/database'; to the top of the test file
2. run npx react-native start &
3. run npx detox test -c ./e2e/test.spec.js
Configuration
babel.config.js:
module.exports = {
presets: [
[
'babel-preset-env',
{
targets: {
node: 'current'
}
}
]
]
};
package.json:
{
"name": <omitted>,
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "react-scripts jest",
"lint": "eslint .",
"preinstall": "node scripts/pre-install.js",
"appium": "appium",
"build:android": "scripts/build-android.sh",
"build:ios": "scripts/build-ios.sh",
"test:android": "appium-helper --platform android",
"test:ios": "appium-helper --platform ios",
"test:local-e2e": "OS=both scripts/run-local-tests.sh",
"run-emulator:android": "scripts/run-android-emulator.sh",
"kill-emulator:android": "scripts/kill-android-emulator.sh"
},
"dependencies": {
"#react-native-firebase/app": "^6.0.2",
"#react-native-firebase/auth": "^6.0.2",
"#react-native-firebase/database": "^6.0.2",
"babel-plugin-dynamic-import-node": "^2.3.0",
"detox": "15.1.3",
"geocodio-library-node": "^1.0.0",
"prettier": "^1.19.1",
"react": "16.12.0",
"react-native": "0.61.5",
"react-native-animatable": "^1.3.3",
"react-native-collapsible": "^1.5.1",
"react-native-gesture-handler": "^1.4.1",
"react-native-reanimated": "^1.7.0",
"react-native-screens": "^2.0.0-alpha.27",
"react-native-segmented-control-tab": "^3.4.1",
"react-native-testing-library": "^1.11.1",
"react-navigation": "^4.0.10",
"react-navigation-stack": "1.9.3"
},
"devDependencies": {
"#babel/core": "^7.8.3",
"#babel/runtime": "^7.8.3",
"#react-native-community/eslint-config": "^0.0.6",
"appium": "1.16.0",
"babel-jest": "^25.1.0",
"babel-preset-env": "1.7.0",
"babel-preset-react-native": "4.0.1",
"babel-preset-react-native-stage-0": "1.0.1",
"babel-preset-stage-0": "6.24.1",
"eslint": "^6.5.1",
"jest": "^25.1.0",
"metro-react-native-babel-preset": "^0.58.0",
"prop-types": "15.7.2",
"react-test-renderer": "16.12.0",
"tape-async": "2.3.0",
"tipsi-appium-helper": "3.3.0",
"webdriverio": "5.18.6"
},
"jest": {
"preset": "react-native",
"transformIgnorePatterns": [
"node_modules/(?!((jest-)?react-native|react-navigation|#react-navigation|#react-native-firebase.*))"
],
"transform": {
"^.+\\.js$": "babel-jest"
},
"setupFiles": [
"./node_modules/react-native-gesture-handler/jestSetup.js",
"react-native/jest/setup.js",
"./jest/setup.js"
]
},
"detox": {
"configurations": {...},
"test-runner": "jest"
}
}
Device and Verbose Detox Logs
● Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
.../node_modules/#react-native-firebase/database/lib/index.js:18
import { isBoolean, isNumber, isString } from '#react-native-firebase/app/lib/common';
^^^^^^
SyntaxError: Cannot use import statement outside a module
> 1 | import database from '#react-native-firebase/database';
Environment (please complete the following information):
- Detox: 15.1.3
- React Native: 0.61.5
- Node: 13.5.0
- Device: Dell XPS 13 2019
- OS: Arch Linux
- Test-runner: Jest+jasmine