firebase deploy is giving me this error message:
async function asyncFunction() {
^^^^^^^^
SyntaxError: Unexpected token function
Here's my code:
async function asyncFunction() {
await getText2Speech(word, 'mp3', 'es-ES_EnriqueVoice')
}
asyncFunction();
getText2Speech is a 75-line function that runs perfectly when I call it without async or await.
I have the Node.js 8 runtime in my functions/package.json:
"engines": {
"node": "8"
},
I have Node up to date on my computer:
node -v
v11.2.0
It seems odd that the unexpected token is function, not async. It seems that firebase deploy recognizes async but I have the syntax wrong? es-lint can't find anything wrong with my code.
Could the problem be this:
npm list --depth 0 -g
├── UNMET PEER DEPENDENCY firebase-admin#6.2.0
npm ERR! peer dep missing: firebase-admin#~6.0.0, required by firebase-functions#2.1.0
If I roll back to firebase-admin#~6.0.0 will async await work?
The problem was that something was pointing to eslint v4.5.0, which doesn't support ES2017. I had eslint v5.9.0 installed but eslint -v always returned v4.5.0. I used find . -name 'eslint' to remove every copy of eslint, there were lots of versions, all other my computer. npm uninstall -g eslint doesn't get every copy of eslint. When eslint -v returned nothing then firebase deploy worked.
async/await was deploying on my other computer, then today it stopped deploying. I checked the package.json in the functions folder on both computers, and both were missing
"engines": {
"node": "8"
},
Adding this line, both computers now deploy async/await. I don't know how this object dropped out of the package.json file, and I don't know if this fix will continue to work, but I'll cross my fingers!
Related
I am trying the Design Automation Tutorial for Revit.
I am getting the following error.
Can someone help me fix this error.
TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of ReadStream
at new NodeError (c:\Users\roshan.kerketta\Desktop\Digital\Forge\ModelDesignAutomation\SampleDesignAutomation\lib\internal\errors.js:372:5)
at write_ (c:\Users\roshan.kerketta\Desktop\Digital\Forge\ModelDesignAutomation\SampleDesignAutomation\lib\_http_outgoing.js:742:11)
at ClientRequest.end (c:\Users\roshan.kerketta\Desktop\Digital\Forge\ModelDesignAutomation\SampleDesignAutomation\lib\_http_outgoing.js:855:5)
at Request._end (c:\Users\roshan.kerketta\Desktop\Digital\Forge\ModelDesignAutomation\SampleDesignAutomation\node_modules\superagent\lib\node\index.js:1282:9)
at Request.end (c:\Users\roshan.kerketta\Desktop\Digital\Forge\ModelDesignAutomation\SampleDesignAutomation\node_modules\superagent\lib\node\index.js:1000:8)
at c:\Users\roshan.kerketta\Desktop\Digital\Forge\ModelDesignAutomation\SampleDesignAutomation\node_modules\superagent\lib\request-base.js:282:12
at new Promise (<anonymous>)
at RequestBase.then (c:\Users\roshan.kerketta\Desktop\Digital\Forge\ModelDesignAutomation\SampleDesignAutomation\node_modules\superagent\lib\request-base.js:264:31)
at c:\Users\roshan.kerketta\Desktop\Digital\Forge\ModelDesignAutomation\SampleDesignAutomation\node_modules\forge-apis\src\ApiClient.js:394:7
at processTicksAndRejections (node:internal/process/task_queues:96:5) {code: 'ERR_INVALID_ARG_TYPE', statusCode: undefined, stack: 'TypeError [ERR_INVALID_ARG_TYPE]: The "chunk"…ions (node:internal/process/task_queues:96:5)', message: 'The "chunk" argument must be of type string …nt8Array. Received an instance of ReadStream', toString: ƒ, …}
Thanks Rahul for spotting the issue! I can reproduce what #JohnKuldeepRoshanKerketta experienced in Forge SDK (forge-apis) in 0.9.0. By the hint of error, I updated the tutorial code(line 509,510) to use readFile, instead of file stream. Now it works well with 0.9.0.
I posted the Issue with tutorial
https://github.com/Autodesk-Forge/learn.forge.designautomation/issues/31
// 2. upload inputFile
const inputFileNameOSS = `${new Date().toISOString().replace(/[-T:\.Z]/gm, '').substring(0,14)}_input_${_path.basename(req.file.originalname)}`; // avoid overriding
try {
//let contentStream = _fs.createReadStream(req.file.path);
let fileContent = _fs.readFileSync(req.file.path);
await new ForgeAPI.ObjectsApi().uploadObject(bucketKey, inputFileNameOSS, req.file.size, fileContent, {}, req.oauth_client, req.oauth_token);
}
I want to understand what the error means, so it could help me fix the error., though it might be basic.
If your goal is to understand this specific error, then you can read this question/answer where it is best asked/explained. However since this is coming from Forge's nodejs apis, I think you did not write this code and you should not be concerned with it.
My best guess is you have somehow managed to upgrade the nodejs package forge-api to 0.9.0 and the rest of the tutorial repo/code is not compatible with it. You can check this with the following command:
cd {repo_folder}
npm ls -depth=0
You should see the following result:
├── autodesk.forge.designautomation#3.0.5
├── body-parser#1.20.0
├── cookie-session#1.4.0
├── express#4.18.1
├── forge-apis#0.8.6
├── form-data#4.0.0
├── multer#1.4.4
└── socket.io#4.5.1
If your forge-apis is showing 0.9.0 instead of 0.8.6, then it explains the error you have. To downgrade it, you can either delete your node_modules folder, undo any changes to package.json and/or package-lock.json and run npm install again.
Alternatively you can also explicitly downgrade the forge-api module.
cd {repo_folder}
npm install forge-apis#0.8.6 -save
npm ls -depth=0
I am getting this error when trying to build a Clojurescript project with shadow-cljs. I've tried looking for syntax errors as described here but I can get the same the error with a single line and a single import although not all imports cause the same error.
This compiles:
(ns campfire.core)
(defn init [] (println "ok"))
This doesn't:
(ns campfire.core
(:require ["bugout" :as b]))
(defn init [] (println "ok"))
The output from the above example is:
shadow-cljs - config: /home/ru/Projects/campfire/shadow-cljs.edn
shadow-cljs - HTTP server available at http://localhost:3000
shadow-cljs - server version: 2.11.18 running at http://localhost:9630
shadow-cljs - nREPL server started on port 8777
shadow-cljs - watching build :frontend
[:frontend] Configuring build.
[:frontend] Compiling ...
[:frontend] Build failure:
The required JS dependency "readable-stream/writable.js" is not available, it was required by "node_modules/stream-browserify/index.js".
Dependency Trace:
campfire/core.cljs
node_modules/bugout/index.js
node_modules/bs58check/index.js
node_modules/create-hash/browser.js
node_modules/cipher-base/index.js
node_modules/stream-browserify/index.js
Searched for npm packages in:
/home/ru/Projects/campfire/node_modules
See: https://shadow-cljs.github.io/docs/UsersGuide.html#npm-install
package.json
{
"name": "campfire",
"version": "0.0.1",
"private": true,
"scripts": {
"build": "shadow-cljs release frontend"
},
"devDependencies": {
"shadow-cljs": "2.11.18"
},
"dependencies": {
"bugout": "^0.0.10",
"webtorrent": "^0.114.1"
}
}
shadow-cljs.edn
{:source-paths
["src/dev"
"src/main"
"src/test"]
:dependencies
[]
:dev-http {3000 "public"}
:nrepl {:port 8777}
:builds
{:frontend
{:target :browser
:modules {:main {:init-fn campfire.core/init}}}}}
I've seen similar build errors that were fixed by clearing .shadow-cljs etc and rebuilding but nothing like that seems to be helping. I'm new to shadow so apologies if this is something obvious. Does anyone have any idea what's going on here?
Update
So it looks like what's happening is that stream-browserify 2.0.2 requires readable stream ^2.0.2 which npm installs in the nested node_modules folder. Elsewhere readable-stream 3.6.0 is being installed in top level node_modules. Shadow is trying to resolve writer.js against the 3.6.0 version of readable stream instead of the 2.0.2 version.
Confusingly though, stream-browserify isn't a dependency of cipher-base as given in the dependency trace but of node-libs-browser which is itself a dependency of shadow-cljs.
Is it possible that this is a bug in shadow or is it expected behaviour?
Update 2
I've created an example repo that replicates what I'm seeing as simply as I can here.
Did you actually install the shadow-cljs dependency in the project? Does the directory node_modules/shadow-cljs exist?
I see it listed in devDependencies so it should be installed but it might not be if you never actually called npm install in the project or npm is set to production mode which won't install devDependencies. All of this is part of the node-libs-browser package which seems to be missing as well and should have been installed due to being a dependency of shadow-cljs.
Based on the link in your first error message, it says to npm install whatever's missing.
If you didn't run npm install, that by itself will install what's in your package.json.
If that's not the issue, then npm i readable-stream may help.
I'm using JSPM 0.16.42 which uses SystemJS, I've tried both angular-translate and angular-route, both of which are on github endpoints.
However, for both of them angular throws the same error
argument module is not a function
when using them in ES6 syntax as follows:
import AngularRoute from 'angular-route';
angular.module('app', [AngularRoute]);
I'm using babel as a transpiler. The object I get back from the import seems to be empty. Following is the relevant part of my config.js file:
System.config({
baseURL: "/",
defaultJSExtensions: true,
transpiler: "babel",
babelOptions: {
"optional": [
"runtime",
"optimisation.modules.system"
]
},
paths: {
"github:*": "jspm_packages/github/*",
"npm:*": "jspm_packages/npm/*"
},
map: {
"angular-route": "github:angular/bower-angular-route#1.5.8",
"angular-translate": "github:angular-translate/bower-angular-translate#2.11.1",
}...
EDIT: When I tried to install angular-translate with an npm endpoint I got the error http://errors.angularjs.org/1.5.8/$injector/unpr?p0=e
on the following line in angular.js
return new ErrorConstructor(message);
which I guess is a bit of progress but still doesn't solve my issue obviously
EDIT#2: I got angular-route to work with the help of #artem by using the npm endpoint, for some reason the github endpoint did not work so I used jspm install npm:angular-route. Further investigation is needed as to why the github package did not work and the npm package did
EDIT#3: I have overriden the package configuration as you can see below, though that didn't help
"npm:angular-translate#2.11.1": {
"format": "global",
"dependencies": {
"angular": ">=1.2.26"
},
"shim": {
"angular-translate": {
"deps": "angular"
}
}
}
I eventually fixed it by installing angular-translate as well as angular-route via their npm endpoints instead of the default (github) endpoints, using
jspm install npm:angular-route
&
jspm install npm:angular-translate -o '{dependencies: { angular: ">=1.2.26" } }'
The override for angular-translate was needed since jspm did not understand the original dependency syntax correctly which was angular: ">= 1.2.26 <=1.6" as described in this github issue
Here is not-so-minimal, not-really-self-contained example for angular-translate with systemjs:
npm install jspm
./node_modules/.bin/jspm install github:angular-translate/angular-translate
keep pressing <ENTER>, accepting all the default values
create file test.js
import AngularTranslate from 'angular-translate/angular-translate';
console.log(AngularTranslate);
create file index.html
<!doctype html>
<html>
<head>
<script src="jspm_packages/system.src.js"></script>
<script src="config.js"></script>
<script>
System.import('./test.js');
</script>
</head>
<body>
</body>
</html>
open it in the browser:
Failed to load resource: the server responded with a status of 404 (File not found)
undefined:1 Uncaught (in promise) Error: (SystemJS) XHR error (404 File not found) loading
http://localhost:8035/jspm_packages/github/angular-translate/angular-translate#2.11.1.js(…)
Why that file isn't there? It's supposed to be created by jspm, if you had installed angular-translate from npm it would have contained
module.exports = require("npm:angular-translate#2.11.1/dist/angular-translate.js");
which is just a redirect from symbolic package name (the name of that .js file) to that package main file, as specified in package.json:
"main": "dist/angular-translate.js",
But angular-translate is from github, there is no dist there. That's why jspm did not create the redirect file - there is nothing to redirect to.
No problem, just build it from the source we got from github:
cd jspm_packages/github/angular-translate/angular-translate#2.11.1/
npm install
npm run-script build
cd ../../../..
and fix mapping in config.js:
map: {
"angular-translate/angular-translate": "github:angular-translate/angular-translate#2.11.1/dist/angular-translate",
open index.html in the browser again:
system.src.js:122 Uncaught (in promise) Error: (SystemJS) angular is not defined(…)
No problem, angular is already installed as angular-translate dependency, just tell systemjs when and how to load it.
add to config.js:
meta: {
"angular-translate/angular-translate": {
"deps": ["angular"]
}
},
map: {
"angular": "github:angular-translate/angular-translate#2.11.1/node_modules/angular/angular",
NOTE: You don't need to specify format for angular-translate. SystemJS auto-detects it correctly - it could be loaded as either 'amd' or 'cjs', but it will not work as 'global'. Also, you probably did not start by installing angular-translate, so you already have angular.js file and mapping in place somewhere.
Open index.html in the browser again. It prints in the console:
pascalprecht.translate
Yes angular-translate exports a string - seems to be typical for angular1 modules.
I have no experience with angular.js, so I declare it a success and stop here.
PS Why angular-route worked when you install it from npm, and did not work from github?
When installed from npm, jspm created a file named jspm_packages/npm/angular-route#1.5.8.js, containing
module.exports = require("npm:angular-route#1.5.8/index.js");
because package.json for angular-route has
"main": "index.js",
which is correct and works for you.
When installed from github, jspm created similar file jspm_packages/github/angular/bower-angular-route#1.5.8.js, but this time it points to a different file
module.exports = require("github:angular/bower-angular-route#1.5.8/angular-route");
because someone put an override in jspm registry there at https://github.com/jspm/registry/blob/master/package-overrides/github/angular/bower-angular-route%401.3.0.json
because bower.json for bower-angular-route has
"main": "./angular-route.js",
Maybe it's an oversight, maybe it's correct and works for them - I don't know.
TL;DR It's not a good idea to use package manager for installing software, if the software was not packaged properly for that package manager.
I'm using protractor with jasmine-reporters 2.0.7
I tried to use the modifySuiteName option to modify suite names.
This is what in my conf.js:
multiCapabilities: [{
browserName: 'firefox'
}, {
browserName: 'chrome'
}],
onPrepare: function() {
var jasmineReporters = require('jasmine-reporters');
return browser.getProcessedConfig().then(function(config) {
var browserName = config.capabilities.browserName;
jasmine.getEnv().addReporter(
new jasmineReporters.JUnitXmlReporter({
savePath: 'c://scripts',
filePrefix: browserName,
consolidateAll: true,
modifySuiteName: function(generatedSuiteName, suite) {
return browserName+ '.' + generatedSuiteName;}
}));
});
},
I suppose to see
testsuite name="chrome.Demo App"
in chrome.xml
and
testsuite name="firefox.Demo App"
in firefox.xml
But I can only see
testsuite name="Demo App"
in both files.
Is there anything wrong in my code?
Okay now I figure out that my issue is caused by a stupid mistake.
I'm using windows 8 and running cmd under the folder c:\scripts.
I'm so new to nodejs and npm that during the set-up process I used npm install --save-dev jasmine-reporters#^2.0.0 and few days later I used npm install -g jasmine-reporters#latest
So there are 2 jasmine-reporters in my system, one in C:\Users\xxx\AppData\Roaming\npm\node_modules\jasmine-reporters
and another in C:\scripts\node_modules\jasmine-reporters,
with version 2.0.7 and 2.0.0 in package.json, respectively.
I just update my jasmine-reporters in C:\scripts\node_modules to 2.0.7 and the script finally works!
Thanks for your time, I really appreciate it.
As far as i see, there is no fault in your code. If your code is generating chrome and firefox xml's then everything with your configuration should be fine. Your code is working perfectly fine in my protractor. I am using Jasmine 2.3.1 with protractor 2.1.0. Try updating your protractor and jasmine framework to the latest version and then run your test suite. To update your jasmine run the below command -
npm update -g jasmine
Also if you have not added the framework tag after multiCapabilities tag in your conf.js file then you should be doing so as shown below -
framework: 'jasmine2',
Hope this solves your issue.
When using Chrome I am getting an error via the Mocha test runner, captured as part of afterEach with this.currentTest.err.
I am compiling coffeescript with browserify with the debug option using the awesome coffeeify plugin. This produces a single compiled file bundle.js with a sourceMappingURL=data:... that allows me to view and debug the original coffeescript directly.
Unfortunately when I access the err.stack in the afterEach Mocha hook, the stack contains references to bundle.js and not the corresponding .coffee files, which would be much more useful.
Here is some sample code with browserify.
First, installing it (for convenience) with npm:
$ npm install -g browserify; npm install coffeeify
x.coffee
try
throw Error("Thrown.")
catch err
console.log err.stack
Convert to x.js with:
$ browserify -t coffeeify x.coffee -d > x.js
x.html
<html>
<head>
<script src='x.js'></script>
</head>
<body></body>
</html>
If one opens this in Chrome the dev tools will show x.js, x.coffee (from the sourceMapURL) and x.html.
When we run this HTML page we get the following output to the console:
Error: Thrown.
at Error ()
at Object. (file://localhost/Users/bmh/tmp/x.js:5:9)
at i (file://localhost/Users/bmh/tmp/x.js:1:219)
at err (file://localhost/Users/bmh/x.js:1:382)
at file://localhost/Users/bmh/tmp/x.js:1:400
What we would expect is to have the trace refer to the .coffee file, looking something like this (which I am making up here for illustrative purposes):
Error: Thrown.
at Error ()
at Object. (file://localhost/Users/bmh/tmp/x.coffee:2:5)
Has anyone had any success converting the error stack to one that refers to the items at their source map locations?
I'm not sure about coffeeify, but the source-map-support module adds .stack support for code bundled with browserify. Just npm install source-map-support and put require('source-map-support').install() at the top of your code.