Firebase function deploy not working: SyntaxError: Unexpected token '?' - javascript

The problem is the same as this question: Firebase Cloud Functions Deploy Error- SyntaxError: Unexpected token '?'
and I've tried all the answers but nothing seems to work.
This is what I get when I try and deploy functions (even the ones that were deploying fine a week ago):
Error: Error occurred while parsing your function triggers.
/Users/islamariful/node_modules/firebase-admin/lib/app/firebase-namespace.js:84
this.INTERNAL = new FirebaseNamespaceInternals(appStore ?? new lifecycle_1.AppStore());
^
SyntaxError: Unexpected token '?'
at wrapSafe (internal/modules/cjs/loader.js:1052:16)
at Module._compile (internal/modules/cjs/loader.js:1100:27)
at Module._compile (pkg/prelude/bootstrap.js:1394:32)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1156:10)
at Module.load (internal/modules/cjs/loader.js:984:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Module.require (internal/modules/cjs/loader.js:1024:19)
at Module.require (pkg/prelude/bootstrap.js:1338:31)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/Users/islamariful/node_modules/firebase-admin/lib/default-namespace.js:19:30)
This is my package.json file:
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"lint": "eslint .",
"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": "16"
},
"main": "index.js",
"dependencies": {
"axios": "^0.21.1",
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.14.1",
"pdfmake": "^0.2.2"
},
"devDependencies": {
"eslint": "^7.6.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-jsdoc": "^36.0.7",
"firebase-functions-test": "^0.2.0"
},
"private": true
}
I've tried multiple things but still can't get this to work. Any ideas on how I can fix this?

Related

Unexpected token 'export' when trying to use the Preact plugin in Next.js

I am currently trying to migrate a Next.js project from React --> Preact.
I have added next-plugin-preact as a dependency and I changed my config also.
Here is the next.config.js:
// #ts-check
const configureBundleAnalyzer = require("#next/bundle-analyzer");
const withPreact = require("next-plugin-preact");
/** #type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
compress: true,
images: {
domains: ["firebasestorage.googleapis.com", "localhost", "lh3.googleusercontent.com", "source.unsplash.com"],
},
i18n: {
locales: ["en"],
defaultLocale: "en",
},
};
const withBundleAnalyzer = configureBundleAnalyzer({ enabled: process.env.ANALYZE_BUNDLE === "true" });
module.exports = withBundleAnalyzer(withPreact(nextConfig));
And then I tried to run pnpm run build but it did nothing. Just killed the script right away.
Then again I tried to run the dev server with pnpm run dev but it threw this error:
:\Default_Folders\Desktop\Projects\Javascript + Dart\AppName\web\node_modules\.pnpm\preact#10.11.3\node_modules\preact\compat\server.browser.js:1
export {
^^^^^^
SyntaxError: Unexpected token 'export'
at internalCompileFunction (node:internal/vm:74:18)
at wrapSafe (node:internal/modules/cjs/loader:1141:20)
at Module._compile (node:internal/modules/cjs/loader:1182:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
at Module.load (node:internal/modules/cjs/loader:1081:32)
at Module._load (node:internal/modules/cjs/loader:922:12)
at Module.require (node:internal/modules/cjs/loader:1105:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (D:\Default_Folders\Desktop\Projects\Javascript + Dart\AppName\web\node_modules\.pnpm\next#13.1.5_ive3jjn476xyi3ikfsqwmh5x74\node_modules\next\dist\server\render.js:7:45) at Module._compile (node:internal/modules/cjs/loader:1218:14)
I tried to look into the file in preact/compat/server.browser.js and this is what's present:
export {
renderToString as renderToStaticMarkup, renderToString
} from 'preact-render-to-string';
So I tried to temporarily just change the contents of the file to:
const {
renderToString: renderToStaticMarkup, renderToString
} = require('preact-render-to-string');
module.exports = { renderToStaticMarkup, renderToString }
and then it threw this error:
Error: Next.js requires react >= 18.2.0 to be installed.
at Object.<anonymous> (D:\Default_Folders\Desktop\Projects\Javascript + Dart\AppName\web\node_modules\.pnpm\next#13.1.5_ive3jjn476xyi3ikfsqwmh5x74\node_modules\next\dist\build\webpack-config.js:1756:11)
at Module._compile (node:internal/modules/cjs/loader:1218:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
at Module.load (node:internal/modules/cjs/loader:1081:32)
Here is my package.json if needed:
{
"name": "app_name",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"browserslist": [
"chrome 90",
"edge 90",
"firefox 90",
"opera 90",
"safari 14"
],
"dependencies": {
"#next/font": "latest",
"#react-icons/all-files": "^4.1.0",
"firebase": "^9.14.0",
"next": "^13.1.5",
"next-plugin-preact": "^3.0.7",
"nprogress": "^0.2.0",
"preact": "^10.11.3",
"preact-render-to-string": "^5.2.6",
"react": "npm:#preact/compat#^17.1.2",
"react-dom": "npm:#preact/compat#^17.1.2",
"react-hot-toast": "^2.4.0",
"react-ssr-prepass": "npm:preact-ssr-prepass#^1.2.0",
"sharp": "^0.31.3"
},
"devDependencies": {
"#next/bundle-analyzer": "^13.1.2",
"#types/node": "^18.11.9",
"#types/nprogress": "^0.2.0",
"#types/react": "^18.0.25",
"#typescript-eslint/eslint-plugin": "^5.46.0",
"autoprefixer": "^10.4.13",
"eslint": "^8.28.0",
"eslint-config-next": "^13.0.5",
"postcss": "^8.4.19",
"prettier": "^2.8.0",
"prettier-plugin-tailwindcss": "^0.2.0",
"tailwindcss": "^3.2.4",
"typescript": "^4.9.3"
}
}
Can anyone help?

How to fix "cannot find module'./node'' while compiling with pkg

the nodejs script works when I do node main.js but when I compile it into an executable with pkg it gives me this error :
pkg/prelude/bootstrap.js:1876
throw error;
^
Error: Cannot find module './node'
Require stack:
C:\snapshot\project\node_modules\hookcord\node_modules\snekfetch\src\index.js
C:\snapshot\project\node_modules\hookcord\src\fire.js
C:\snapshot\project\node_modules\hookcord\src\index.js
C:\snapshot\project\node_modules\hookcord\index.js
C:\snapshot\project\main.js
If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath.
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function._resolveFilename (pkg/prelude/bootstrap.js:1955:46)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at Module.require (pkg/prelude/bootstrap.js:1855:31)
at require (node:internal/modules/cjs/helpers:102:18)
at Object. (C:\snapshot\project\node_modules\hookcord\node_modules\snekfetch\src\index.js:3:19)
at Module._compile (pkg/prelude/bootstrap.js:1930:22)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\snapshot\project\node_modules\hookcord\node_modules\snekfetch\src\index.js',
'C:\snapshot\project\node_modules\hookcord\src\fire.js',
'C:\snapshot\project\node_modules\hookcord\src\index.js',
'C:\snapshot\project\node_modules\hookcord\index.js',
'C:\snapshot\project\main.js'
],
pkg: true
}
I have a similar error while packaging a NestJS application.
Here is my package.json file
{
"bin": "dist/main.js",
"pkg": {
"assets": [
"node_modules/**/*"
],
"outputPath": "bin",
"scripts": "dist/**/*.js",
"targets": [
"node14-linux-x64",
"node14-macos-x64"
]
},
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"build2": "pkg package.json",
"start": "nest start --watch",
"start:dev": "nest start --watch",
"start:prod": "node dist/main",
},
"dependencies": {
"#nestjs/common": "^7.0.0",
"#nestjs/core": "^7.0.0",
"#nestjs/platform-express": "^7.0.0",
"#nestjs/schedule": "^0.4.3",
"#nestjs/typeorm": "^7.1.4",
"#sentry/node": "^6.7.2",
"#sentry/tracing": "^6.7.2",
"axios": "^0.21.1",
"class-validator": "^0.12.2",
"fast-speedtest-api": "^0.3.2",
"jsonpath": "^1.1.0",
"moment": "^2.29.1",
"mysql": "^2.18.1",
"mysql2": "^2.2.5",
"querystring": "^0.2.1",
"queue-system": "^3.0.2",
"rimraf": "^3.0.2",
"rxjs": "^6.5.4",
"typeorm": "^0.2.27",
"winston": "^3.3.3",
"xml-js": "^1.6.11",
"xml2json": "^0.12.0"
},
"devDependencies": {
"#nestjs/cli": "^7.0.0",
"#nestjs/schematics": "^7.0.0",
"#nestjs/testing": "^7.0.0",
"#types/express": "^4.17.3",
"#types/node": "^13.9.1",
"#typescript-eslint/eslint-plugin": "3.9.1",
"#typescript-eslint/parser": "3.9.1",
"eslint": "7.7.0",
"eslint-plugin-import": "^2.20.1",
"ts-loader": "^6.2.1",
"ts-node": "9.0.0",
"tsconfig-paths": "^3.9.0",
"typescript": "^3.7.4"
}
}
The command I am running is: pkg package.json and it seems to run without any error. However, when running the binary I have similar errors:
error: Error: Cannot find module 'esprima'
Require stack:
- aesprim
1) If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath.
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function._resolveFilename (pkg/prelude/bootstrap.js:1955:46)
at Function.resolve (internal/modules/cjs/helpers.js:107:19)
at Object.<anonymous> (/snapshot/app/node_modules/jsonpath/lib/aesprim.js:4:20)
at Module._compile (pkg/prelude/bootstrap.js:1930:22)
at Object.<anonymous> (/snapshot/app/node_modules/jsonpath/lib/aesprim.js:15:11)
at Module._compile (pkg/prelude/bootstrap.js:1930:22)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ 'aesprim' ],
pkg: true
},
I tried to install esprima manually and create the package again, but the error is the same.
Thanks for your help

nodejs: SyntaxError: Unexpected identifier

I'm taking a look at https://github.com/intoli/remote-browser. I'm working in win10 with node 11.5. I've followed the instructions at the bottom of the repo:
# Clone the repository.
git clone https://github.com/intoli/remote-browser.git
cd remote-browser
# Install the dependencies.
yarn install
# Build the project.
yarn build
# Run the tests.
yarn test
Now when I try to run it using :
$ node src/index.js
E:\ENVS\js\remote-browser\src\index.js:1
(function (exports, require, module, __filename, __dirname) { import Browser from './browser';
^^^^^^^
SyntaxError: Unexpected identifier
at new Script (vm.js:83:7)
at createScript (vm.js:267:10)
at Object.runInThisContext (vm.js:319:10)
at Module._compile (internal/modules/cjs/loader.js:684:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:774:12)
at executeUserCode (internal/bootstrap/node.js:342:17)
How can I get this working?
edit index.js:
import Browser from './browser';
import ConnectionProxy from './connections/proxy';
export default Browser;
export { Browser };
export { ConnectionProxy };
export * from './errors';
export * from './launchers';
edit2:
{
"name": "remote-browser",
"version": "0.0.15",
"description": "A low-level browser automation framework built on top of the Web Extensions API standard. ",
"main": "index.js",
"repository": "git#github.com:intoli/remote-browser.git",
"author": "Intoli, LLC <contact#intoli.com>",
"license": "BSD",
"scripts": {
"build": "Set NODE_ENV=production webpack --config webpack",
"build:web": "NODE_ENV=production webpack --config webpack/web-client.config.js",
"postversion": "git push && git push --tags",
"test": "npm run build && NODE_ENV=test mocha --exit --require babel-core/register",
"test-fast": "NODE_ENV=test mocha --exit --require babel-core/register --invert --grep Browser",
"watch": "NODE_ENV=development webpack --watch --config webpack"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-eslint": "^8.0.2",
"babel-loader": "^7.1.2",
"babel-plugin-transform-builtin-extend": "^1.1.2",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.6.1",
"clean-webpack-plugin": "^0.1.17",
"copy-webpack-plugin": "^4.2.1",
"eslint": "^4.11.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-loader": "^1.9.0",
"eslint-plugin-import": "^2.8.0",
"imports-loader": "^0.7.1",
"jimp": "^0.2.28",
"mocha": "^4.0.1",
"null-loader": "^0.1.1",
"source-map-support": "^0.5.0",
"webextension-polyfill": "^0.2.1",
"webpack": "^3.8.1",
"webpack-chrome-extension-reloader": "^0.6.6"
},
"dependencies": {
"chromedriver": "^2.37.0",
"express": "^4.16.2",
"express-ws": "^3.0.0",
"geckodriver": "^1.11.0",
"isomorphic-fetch": "^2.2.1",
"portfinder": "^1.0.13",
"selenium-webdriver": "^4.0.0-alpha.1",
"simple-websocket": "^5.1.0",
"ws": "^3.3.2"
}
}
You can't run node src/index.js. When you run yarn build it will create a new folder dist in the root folder, which has all the source code. Go to this folder and find the index.js file, open this to learn more.

Node.js - "Cannot find module 'module.js' "

I'm using Heroku and I get this error..
2016-10-10T03:34:11.188366+00:00 app[web.1]: Error: Cannot find module 'module1.js'
2016-10-10T03:34:11.188369+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:339:15)
2016-10-10T03:34:11.188370+00:00 app[web.1]: at Function.Module._load (module.js:290:25)
2016-10-10T03:34:11.188371+00:00 app[web.1]: at Module.require (module.js:367:17)
2016-10-10T03:34:11.188371+00:00 app[web.1]: at require (internal/module.js:20:19)
2016-10-10T03:34:11.188372+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:42:15)
2016-10-10T03:34:11.188373+00:00 app[web.1]: at Module._compile (module.js:413:34)
2016-10-10T03:34:11.188374+00:00 app[web.1]: at Object.Module._extensions..js (module.js:422:10)
2016-10-10T03:34:11.188374+00:00 app[web.1]: at Module.load (module.js:357:32)
2016-10-10T03:34:11.188375+00:00 app[web.1]: at Function.Module._load (module.js:314:12)
2016-10-10T03:34:11.188375+00:00 app[web.1]: at Function.Module.runMain (module.js:447:10)
app.js
/**CUSTOM_MODULES**/
var module1 = require('module1.js');
/**MODULES_END**/
module1.js
function module1(){
//My code
}
module.exports = module1;
module1.js is in the same directory as my app.js.
I have tried countless things but nothing seems to work.
I have tried:
var module1 = require('module1.js');
var module1 = require('./module1.js');
var module1 = require('../module1.js');
var module1 = require('module1');
package.json : app.js
{
"name": "nano-server",
"version": "1.0.0",
"description": "",
"main": "server.js",
"dependencies": {
"express": "^4.14.0",
"mysql": "^2.11.1",
"socket.io": "^1.4.8",
"module1": "0.0.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "ISC"
}
package.json : module1
{
"name": "module1",
"version": "0.0.0",
"description": "get something",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": {
"name": "sergey"
},
"license": "BSD-2-Clause",
"readme": "ERROR: No README data found!",
"_id": "module1#0.0.0",
"dist": {
"shasum": "dc9b96f8a43b596bf735da4d2004ba410429bde0",
"tarball": "https://registry.npmjs.org/module1/-/module1-0.0.0.tgz"
},
"_from": "module1#latest",
"_npmVersion": "1.3.11",
"_npmUser": {
"name": "sergey-user",
"email": "aaa#mail.ru"
},
"maintainers": [
{
"name": "sergey-user",
"email": "aaa#mail.ru"
}
],
"directories": {},
"_shasum": "dc9b96f8a43b596bf735da4d2004ba410429bde0",
"_resolved": "https://registry.npmjs.org/module1/-/module1-0.0.0.tgz"
}
directory
_server
.git
node_modules
.bin
express
module1
index.js
package.json
mysql
node-mysql
node-uuid
socket.io
package.json
server.js
Try var module1 = require('./module1');
Adding your module as a dependency to your application would resolve this issue. To achieve that try the below command.
npm install module1 --save
Hope this helps!
install npm -g and try again afterwords.
In my case, after trying everything without any success, updating node helped (v10.3.1 -> v12.13.1).

Uncaught Error: Cannot find module './charset.js'

Why am I getting this error?
Uncaught Error: Cannot find module './charset.js'
package.json
{
"name": "app",
"version": "1.0.0",
"description": "Application built with Flux and React.js",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Joe Collins",
"license": "",
"devDependencies": {
"browserify": "*",
"flux": "*",
"gulp": "*",
"reactify": "*",
"vinyl-source-stream": "*",
"object-assign": "*"
},
"dependencies": {
"bufferutil": "^1.2.1",
"charset": "^1.0.0",
"http": "0.0.0",
"react": "^0.14.7",
"react-dom": "^0.14.7",
"socket.io": "^1.4.5",
"utf-8-validate": "^1.2.1"
}
}
gulpfile.js
var gulp = require('gulp');
var browserify = require('browserify');
var reactify = require('reactify');
var source = require('vinyl-source-stream');
gulp.task('browserify', function() {
browserify('./src/js/main.js')
.transform('reactify')
.bundle()
.pipe(source('main.js'))
.pipe(gulp.dest('dist/js'))
});
gulp.task('copy', function() {
gulp.src('src/index.html')
.pipe(gulp.dest('dist'));
gulp.src('src/css/*.*')
.pipe(gulp.dest('dist/css'));
gulp.src('src/js/vendors/*.*')
.pipe(gulp.dest('dist/js'));
});
gulp.task('default', ['browserify', 'copy'], function() {
return gulp.watch('src/**/*.*', ['browserify', 'copy']);
});
App.js
var io = require('socket.io')();
You have to use socket.io-client for client side stuff. I have a hunch that charset.js uses a binary, or something that can't be converted to the browser.
https://github.com/socketio/socket.io-client
I was facing same problem but with some other module I did reinstall with latest and it is working for me
Problem
Error: Cannot find module './charset.js'
1) If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath.
at Function.Module._resolveFilename (module.js:534:15)
at Function.Module._resolveFilename (pkg/prelude/bootstrap.js:1269:46)
at Function.Module._load (module.js:464:25)
at Module.require (module.js:577:17)
at Module.require (pkg/prelude/bootstrap.js:1153:31)
at require (internal/module.js:11:18)
at /snapshot/html/config/configurator-file-api/node_modules/accepts/node_modules/negotiator/lib/negotiator.js:21:16
at Array.forEach (<anonymous>)
at Object.<anonymous> (/snapshot/html/config/configurator-file-api/node_modules/accepts/node_modules/negotiator/lib/negotiator.js:19:18)
at Module._compile (pkg/prelude/bootstrap.js:1243:22)
at Object.Module._extensions..js (module.js:644:10)
at Module.load (module.js:552:32)
at tryModuleLoad (module.js:495:12)
at Function.Module._load (module.js:487:3)
at Module.require (module.js:577:17)
at Module.require (pkg/prelude/bootstrap.js:1153:31)
Solution
cd /var/html/config/configurator-file-api/node_modules/accepts/
npm uninstall negotiator --save
npm install negotiator --save
Yes it is working

Categories

Resources