Vue - Supabase error while doing NPM run npm - vue.js

So I have a Vue application that I was working on. Later I wanted to add a backend to it using Supabase and deploy to Vercel. However, after I added the backend elements to it, it throws the following error when I did npm run serve:
ERROR Failed to compile with 1 error 1:31:54 PM
error in ./src/supabase.js
Module parse failed: Unexpected token (2:24)
File was processed with these loaders:
* ./node_modules/cache-loader/dist/cjs.js
* ./node_modules/babel-loader/lib/index.js
* ./node_modules/eslint-loader/index.js
You may need an additional loader to handle the result of these loaders.
| import { createClient } from "#supabase/supabase-js";
> var supabaseUrl = import.meta.env.VITE_SUPABASE_URL;
| var supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY;
| export var supabase = createClient(supabaseUrl, supabaseAnonKey);
Anyone knows what this means? I have another Vue app that was set up via Vite and it ran fine in local, but not in this Vue app that wasn't set up by Vite.

change your .env variable from VITE_SUPABASE_URL to VUE_APP_SUPABASE_URL and import.meta.env to process.env.
Example:
From this
import { createClient } from '#supabase/supabase-js'
const supabaseUrl = import.meta.env.VITE_SUPABASE_URL
const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY
export const supabase = createClient(supabaseUrl, supabaseAnonKey)
To this
import { createClient } from "#supabase/supabase-js";
const supabaseUrl = process.env.VUE_APP_SUPABASE_URL;
const supabaseAnonKey = process.env.VUE_APP_SUPABASE_ANON_KEY;
export const supabase = createClient(supabaseUrl, supabaseAnonKey);

Related

React native - The native module for Flipper seems unavailable

Im using react redux toolkit. This is my store configuration.
My app doesn't start becouse this warn: The native module for Flipper seems unavailable. Please verify that react-native-flipper is installed as yarn dependency to your project and, for iOS, that pod install is run in the ios
directory.
import {configureStore} from '#reduxjs/toolkit';
import authorization from 'redux/slices/authorization';
const createDebugger = require('redux-flipper').default;
export const store = configureStore({
reducer: {authorization: authorization},
middleware: [createDebugger],
});
// Infer the `RootState` and `AppDispatch` types from the store itself
export type RootState = ReturnType<typeof store.getState>;
// Inferred type: {posts: PostsState, comments: CommentsState, users: UsersState}
export type AppDispatch = typeof store.dispatch;

How Do I Properly Initialize RxDB in a Vue App with global

I'm trying out RxDB for the first time in a Vue 3 app, and getting started is a bit more tricky than I expected (and it's probably my fault).
I installed RxDB with NPM in my project ("rxdb": "^9.20.0"), then I did this in my main.js file:
import { createRxDatabase, RxDatabase } from 'rxdb'
const db = await createRxDatabase({
name: 'MyApp', adapter: 'idb'
})
console.dir(db)
I then get this error:
Uncaught ReferenceError: global is not defined
So I check the docs and found this that I need a global polyfill like this:
(window as any).global = window;
(window as any).process = {
env: { DEBUG: undefined },
};
That looks to be an example using Typescript from Angular. When I try it in Vue, I then get this error:
Invalid assignment target
3 | import { createRxDatabase, RxDatabase } from 'rxdb'
4 |
5 | const db = await createRxDatabase({
| ^
6 | name: 'Avid', adapter: 'idb'
7 | })
10 minutes in and I'm already a mess. 😅 Can someone show me how to properly start up RxDB in a Vue app?
You can't use await in root.
It must be inside async function.
let db
async function initDb() {
db = await createRxDatabase(...)
}
initDb()

Svelte/ Rollup Error “missing global variable name”

When I am importing "AmazonCognitoIdentity" in my Routify project I am getting "missing global variable name" error.
Error message:
bundles src/main.js  dist\build\bundle.js...
LiveReload enabled
(!) Unresolved dependencies
https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
/js/amazon-cognito-identity.min.js (imported by src\pages\_components\Login.svelte)
(!) Missing global variable name
Use output.globals to specify browser global variable names corresponding to external modules
/js/amazon-cognito-identity.min.js (guessing 'amazonCognitoIdentity_min_js')
created dist\build\bundle.js in 2.7s
bundles src/sw.js  dist\sw.js...
created dist\sw.js in 1.6s
Following is my code
import { AmazonCognitoIdentity } from "/js/amazon-cognito-identity.min.js";
const authenticationData = {
Username: userName,
Password: password,
};
const authenticationDetails = new AmazonCognitoIdentity.AuthenticationDetails(
authenticationData
);
console.log(authenticationDetails);
const poolData = {
UserPoolId: "xxxx”
ClientId: "xxxxxxx",
};
const userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
const userData = {
Username: userName,
Pool: userPool,
};
console.log(userData);
const cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
const accessToken = result.getAccessToken().getJwtToken();
console.log(`on sucess: ${accessToken}`);
},
onFailure: function (err) {
console.log(`onfailure: ${err}`);
console.log(err);
},
});
and also I’ve linked the following file in _index.html
<script src="./js/amazon-cognito-identity.min.js"></script>
<script src="./js/amazon-cognito-auth.min.js"></script>
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.7.16.min.js"></script>
And the same process in working good in normal Html ad JavaScript files.
npm i amazon-cognito-identity-js
run this command first then update your import to this:
import { AmazonCognitoIdentity } from 'amazon-cognito-identity-js';
Flowing error is thrown after incorporating
npm i amazon-cognito-identity-js
import { AmazonCognitoIdentity } from 'amazon-cognito-identity-js';
ERROR:
(!) Plugin node-resolve: preferring built-in module 'buffer' over local alternative at 'E:\ec-website\htx-pp-client\node_modules\buffer\index.js', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning
(!) Unresolved dependencies
https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
buffer (imported by node_modules\amazon-cognito-identity-js\es\AuthenticationHelper.js, node_modules\amazon-cognito-identity-js\es\CognitoUser.js, node_modules\amazon-cognito-identity-js\es\CognitoJwtToken.js)
[!] Error: 'AmazonCognitoIdentity' is not exported by node_modules\amazon-cognito-identity-js\es\index.js, imported by src\pages_components\Login.svelte
After adding this line to rollup.config.js
rollup.external = ["AmazonCognitoIdentity", "amazon-cognito-identity-js"];
rollup.output = {
file: "dist/build/bundle.js",
format: "umd",
interop: "esModule",
globals: {
"amazon-cognito-identity-js": "AmazonCognitoIdentity",
},
};
The above error is gone. But at run time throws a new error
Uncaught TypeError: Cannot read property 'AmazonCognitoIdentity' of undefined
I got past this error by adding
import polyfills from "rollup-plugin-node-polyfills";
...
plugins: [
polyfills(),
...
to my rollup.config.js
My guess is, you need to change the import statement so that it is relative:
import { AmazonCognitoIdentity } from "./js/amazon-cognito-identity.min.js";
I don't know where this file is, but you need to have . or .. at the start of the location.
As I'm not an expert I yet cannot explain you why.
import AmazonCognitoIdentity from 'amazon-cognito-identity-js';
Is your import correct?

I can not register my service worker using VUE

I'm trying to create a PWA with VUE.
When trying to register the service worker I do it in the file main.js in the following way:
main.js
import Vue from 'vue'
import App from './App.vue'
import router from './router'
Vue.config.productionTip = false
new Vue({
router,
render: h => h(App)
}).$mount('#app')
const prod = process.env.NODE_ENV === 'production';
const swLocation = '../public/sw-config.js';
if (
prod &&
('https:' === location.protocol || location.host.match(/(localhost|127.0.0.1)/)) &&
navigator.serviceWorker
) {
navigator.serviceWorker.register(swLocation).catch( error => console.log)
console.log('sw register');
}
As you can see my service worker file is called sw-config.js that is in the public folder at the same level as the index.html.
But at the moment of executing npm run build and executing this from a local server with npm http-server I get the message by console: "sw register"
But also the following errors:
A bad HTTP response code (404) was received when fetching the script.
Failed to load resource: net::ERR_INVALID_RESPONSE
I also noticed that this error is not shown in the console the first time the application is executed but if it is reloaded it is when it starts.
I tried to fix it by cleaning all the registered service workers to verify if that was the error but it did not work, this was the code that I used in the Chrome console:
navigator.serviceWorker.getRegistrations().then(function(registrations) { for(let registration of registrations) { registration.unregister() } })
On Chrome Developer Tools I have this:
Chrome=>Dev Tools=>Application=>Service Workers=>Update on reload (selected)
I do not know how to avoid that error in the console, could someone help me?
Thanks!
Everything in public folder is in the root folder of the application after the build.
So your url should be: const swLocation = '/sw-config.js';

Error Gulp browserify require ('material-design-lite') module not found

Browserify error with material-design-lite. I install with npm material-design-lite and other package.
const React = require('react');
const ReactDOM = require('react-dom');
const googleApiLoader = require('./GoogleAPILoader');
const MicroBarChart = require('react-micro-bar-chart');
//const mdl = require('./material.min.js');
const mdl = require('material-design-lite');
Others requires work perfectly. So my workaround is to put the material.min.js in script directory (as commented).
[11:59:18] Starting 'copy'...
events.js:141
throw er; // Unhandled 'error' event
^
Error: module "material-design-lite" not found from "D:\\MyAPP\\app\\scripts\\fake_2a2b1a27.js"
at notFound (D:\countingit\node_modules\gulp-browserify\node_modules\browserify\index.js:803:15)
at D:\MyAPP\node_modules\gulp-browserify\node_modules\browserify\index.js:754:23
at D:\MyAPP\node_modules\gulp-browserify\node_modules\browserify\node_modules\browser-resolve\index.js:185:24
at D:\countingit\node_modules\gulp-browserify\node_modules\browserify\node_modules\resolve\lib\async.js:44:14
at process (D:\MyAPP\node_modules\gulp-browserify\node_modules\browserify\node_modules\resolve\lib\async.js:113:43)
at D:\MyAPP\node_modules\gulp-browserify\node_modules\browserify\node_modules\resolve\lib\async.js:122:21
at load (D:\countingit\node_modules\gulp-browserify\node_modules\browserify\node_modules\resolve\lib\async.js:54:43)
at D:\MyAPP\node_modules\gulp-browserify\node_modules\browserify\node_modules\resolve\lib\async.js:60:22
at D:\MyAPP\node_modules\gulp-browserify\node_modules\browserify\node_modules\resolve\lib\async.js:16:47