ReferenceError: connect is not defined when executing node server.js - angularjs

I am new to Nodejs and AngularJS. I have researched this error on your website and not been able to find an answer. I am working from the book, Pro AngularJS by Adam Freeman, Apress. After reading the post by Sheraz (nodejs connect cannot find static, Jun 21 '14) and the answer by dylants, I have done option 2, npm install serve-static. I updated my server.js code thus:
var connect = require('connect'),
serveStatic = require('serve-static');
var app = connect();
app.use(serveStatic("C:\wamp\www\Projects\ProAngularJS"));
app.listen(5000);
When I type "node C:\wamp\www\Projects\ProAngularJS\server.js" The error I get looks like this:
C:\wamp\www\Projects\ProAngularJS\server.js:1
(function (exports, require, module, __filename, __dirname) { var app = connect(
);
^
ReferenceError: connect is not defined
at Object.<anonymous> (C:\wamp\www\Projects\ProAngularJS\server.js:1:73)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:968:3
I have no idea why I'm getting this error. Maybe I didn't install node correctly?
Any help would be appreciated.
Thx,
Khthulhu

Kindly check whether you have connect module in node_modules, if not install it using npm. Hope this helps.

Related

Nextjs - Unexpected token "export"

I started with NextJS, before that I used React a lot.
I run the app on docker (node:18-alpine) if it makes any difference.
I have API thing that I wrote before and published as NPM module. Now I install it with yarn add sjiamnocna/renette-api, it's ok, I can use it with react.
I have file "next-app/utils/API/initapi.ts" containing
import CAPI from "renette-api"
const API = new CAPI()
API.authenticateWithName('abcdef')
API.authorizeWithKey('12345')
export default API
It gives me SyntaxError: Unexpected token 'export'
Nothing I found worked so far, any idea?
EDIT1:
Suppose it fails during the runtime (running yarn dev) because it's successfully built and served for development. The CMD tells the same thing as the browser
SyntaxError: Unexpected token 'export'
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1026:15)
at Module._compile (node:internal/modules/cjs/loader:1061:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1151:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.renette-api (/home/sjiamnocna/Documents/wrk/docker_test/nginxphppg/next-app/.next/server/pages/index.js:52:18)
at __webpack_require__ (/home/sjiamnocna/Documents/wrk/docker_test/nginxphppg/next-app/.next/server/webpack-runtime.js:33:42) {
page: '/'
}
I have the file in directory next to the pages directory, couldn't that cause anything?
Ok, the solution is "workaround".
I changed the target of my package to ES5, now it exports the old style as NextJS expects it. BUT, if you guys have some trick to make the ES6 imports work, tell me
// before
export default MyClass
// now
module.exports = default
Have a nice day

pdfjs-dist package problem while build process

I am having a problem with the pdfjs-dist package while building processing. It is showing an error in GitLab build image.
node version ---- v14.19.0
pdfjs-dist version-2.13.313
/app/node_modules/pdfjs-dist/build/pdf.js:2440
return this._jsActionsPromise ||= this._transport.getPageJSActions(this._pageIndex);
^^^
SyntaxError: Unexpected token '||='
at wrapSafe (internal/modules/cjs/loader.js:988:16)
at Module._compile (internal/modules/cjs/loader.js:1036:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Module.require (internal/modules/cjs/loader.js:961:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object.<anonymous> (/app/node_modules/#react-pdf-viewer/core/lib/cjs/core.min.js:1:94)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10) {
type: 'SyntaxError'
}
Upgrading to node 16 resolved my problem, you might want to try that (if possible, of course) :)
Downgrading my package version to 2.9.359 has resolved my problem
I had the same situation, with a locally installed Node v14.x too. I did something similar to Elia. D's answer, but since the binary file is self-contained with its own Node runtime, instead of upgrading my local Node version, I solved it by setting the target to use Node v16.

Can not find module './contracts/PetShop.json' - Build artifacts are not sent to /src folder

I am trying to write a simple UI client app which will read the smart contract to fetch some data. However I am stuck in getting the build artifact inside the /src folder. During deployment of the smart contract (migrate) on a local Truffle network, I noticed the build artifact is not getting copied over to src folder. However I have mentioned it in the truffle config file.
truffle config content
const path = require('path');
contracts_build_directory: path.join(__dirname + 'client-app/src/contracts'),
App.js - I have already defined an import statement
import PetShop from './contracts/PetShop.json';
The react app was created using the npm module create-react-app.
But during the deploy, the contract artifact is not copied over to /src - hence it gives could not find module error.
Any help
Thanks
PS C:\Users\HP\new-react> node src/dare.js
node:internal/modules/cjs/loader:998
throw err;
^
Error: Cannot find module './build/contracts/so.json'
Require stack:
- C:\Users\HP\new-react\src\dare.js
at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
at Module._load (node:internal/modules/cjs/loader:841:27)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (C:\Users\HP\new-react\src\dare.js:3:20)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47 {
code: 'MODULE_NOT_FOUND',
requireStack: [ 'C:\\Users\\HP\\new-react\\src\\dare.js' ]
}
The answer to this is very simple, make sure you point your react file to the right path.
enter image description here
Before I referenced the path correctly, it showed an error.
const MyContract = require('./build/contracts/so.json');
To correct the error do this:
const MyContract = require('../build/contracts/so.json');

I got this error while installing react app

I got this error while installing the react app. Perviously, it was working well but, now it started to show this error. How to fix it?
internal/modules/cjs/loader.js:614
throw e;
^
Error: No valid exports main found for 'D:\Programming\react\stores\node_modules\is-promise'
at resolveExportsTarget (internal/modules/cjs/loader.js:611:9)
at applyExports (internal/modules/cjs/loader.js:492:14)
at resolveExports (internal/modules/cjs/loader.js:541:12)
at Function.Module._findPath (internal/modules/cjs/loader.js:643:22)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:941:27)
at Function.Module._load (internal/modules/cjs/loader.js:847:27)
at Module.require (internal/modules/cjs/loader.js:1016:19)
at require (internal/modules/cjs/helpers.js:69:18)
at Object.<anonymous> (D:\Programming\react\stores\node_modules\run-async\index.js:3:17)
at Module._compile (internal/modules/cjs/loader.js:1121:30) {
code: 'MODULE_NOT_FOUND'
}
Aborting installation.
node has failed.
Deleting generated file... node_modules
Deleting generated file... package.json
Done.
i think this issue is related to is-promise issue
https://github.com/then/is-promise/issues/14#issue-606798951
they are working for fixing the bug.

E/configParser - Error message: configuration file cli.js did not export a config object

I am new to protractor, and I successfully setup the protractor in eclipse.I followed this https://www.protractortest.org/#/ link, where conf.js contains:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['todo-spec.js']
};
and spec.js contains:
describe('angularjs homepage todo list', function() {
it('should add a todo', function() {
browser.get('https://angularjs.org');
element(by.model('todoList.todoText')).sendKeys('write first protractor test');
element(by.css('[value="add"]')).click();
var todoList = element.all(by.repeater('todo in todoList.todos'));
expect(todoList.count()).toEqual(3);
expect(todoList.get(2).getText()).toEqual('write first protractor test');
// You wrote your first test, cross it off the list
todoList.get(2).element(by.css('input')).click();
var completedAmount = element.all(by.css('.done-true'));
expect(completedAmount.count()).toEqual(2);
});
});
code as mentioned on the link. But when I execute the conf.js it shows me below error in eclipse's console.
[10:31:25] E/configParser - Error code: 105
[10:31:25] E/configParser - Error message: configuration file D:\Selenium_Workspace\ProtractorJavaScriptProject5\node_modules\protractor\built\cli.js did not export a config object
[10:31:25] E/configParser - Error: configuration file D:\Selenium_Workspace\ProtractorJavaScriptProject5\node_modules\protractor\built\cli.js did not export a config object
at ConfigParser.addFileConfig (D:\Selenium_Workspace\ProtractorJavaScriptProject5\node_modules\protractor\built\configParser.js:141:19)
at Object.initFn [as init] (D:\Selenium_Workspace\ProtractorJavaScriptProject5\node_modules\protractor\built\launcher.js:93:22)
at Object.<anonymous> (D:\Selenium_Workspace\ProtractorJavaScriptProject5\node_modules\protractor\built\cli.js:225:10)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
Please suggest.
Following is my run configuration which worked on my eclipse.
1) Main Tab test is my project folder
2) Protractor Tab
I installed Angularjs Eclipse 1.2 which fail to enable me to choose Nodejs installed by my self, I have to use the embed Nodejs in Angularjs Eclipse 1.2, but this one is lower version can't satisfy my Protractor, thus I copy my high version node.exe into the embed Nodejs install folder to overwrite the lower node.exe. After that all things worked as expected well
Some Google search said Angularjs Eclipse 1.3 can fix the can't choose self installed Nodejs, but I have no luck to get it installed on my Eclipse java Luna and Eclipse jee Luna.

Resources