I am currently working on an express.js Webapp, Im working off the boilerplate app that comes with MS Webmatrix. I am able to run the app on my computer but when i push to nodejitsu or use another computer from which i got the app from git i get an error preventing server start.
app.use(express.compiler({ src: __dirname + '/public', enable: ['less'] })
^
TypeError: Object function createApplication() {
var app = connect();
utils.merge(app, proto);
app.request = { __proto__: req };
app.response = { __proto__: res };
app.init();
return app;
} has no method 'compiler'
at Function.<anonymous> (C:\Users\hoopdog2\Desktop\afterthoughts_nodejs\serv
er.js:197:21)
at Function.app.configure (C:\Users\hoopdog2\Desktop\afterthoughts_nodejs\no
de_modules\express\lib\application.js:399:61)
at Object.<anonymous> (C:\Users\hoopdog2\Desktop\afterthoughts_nodejs\server
.js:188:5)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
The dependencies that that app uses are
"node-uuid": ">= 1.3.3",
"everyauth": ">= 0.2.29",
"nconf": ">= 0.5.1",
"express": ">= 2.5.0",
"jade": ">= 0.18.0",
"less": ">= 1.1.5",
"socket.io": ">= 0.8.7",
"connect": ">=1.8.5",
"recaptcha": ">=1.1.0"
And i am using node version 0.8.7. Any suggestions to what might be causing this error is greatly appreciated
The compiler middleware for Express comes from the Connect framework and as of Jul 2011 Connect no longer includes compiler. So doing express.compiler(...) doesn't work anymore.
A LESS-specific middleware has been created and Express now uses that if you include it in your startup config. express -c less will add this line to the config:
app.use(require('less-middleware')({ src: __dirname + '/public' }));
If you have an older version of Express and Connect, you can add less-middleware to your package.json and add the line above to get it working.
It works pretty much the same as the original compiler, but includes some more bells and whistles.
less-middleware project repository
Thanks to Hector i resolved the issue. I had the wrong version of express installed and changing express to = 2.5.0 from >=2.5.0 and reinstalling dependencies has fixed the issue and i am now able to run the app. Thanks
Related
I got this error on my M2 MacBook, running a project, that worked on my old Intel MacBook. Do you have any idea what the problem is?
I am using bun but npm run dev (node 18) gives me the same error.
The exact same error occurred on other projects.
Package.json dependencies:
"devDependencies": {
"#types/three": "^0.143.1",
"parcel": "^2.7.0"
},
"dependencies": {
"three": "^0.143.0"
}
Console output for bun run dev:
$ parcel src/index.html --open
Error: No native build was found for platform=darwin arch=x64 runtime=node abi=108 uv=1 libc=glibc node=18.7.0
loaded from: /Users/frankmayer/Documents/Git/WorldArchitect/WebGLPreview/node_modules/lmdb and package: #lmdb/lmdb-darwin-x64
at load.path (/Users/frankmayer/Documents/Git/WorldArchitect/WebGLPreview/node_modules/node-gyp-build-optional-packages/index.js:64:9)
at Object.load [as default] (/Users/frankmayer/Documents/Git/WorldArchitect/WebGLPreview/node_modules/node-gyp-build-optional-packages/index.js:20:30)
at Object.<anonymous> (/Users/frankmayer/Documents/Git/WorldArchitect/WebGLPreview/node_modules/lmdb/dist/index.cjs:47:47)
at Module._compile (/Users/frankmayer/Documents/Git/WorldArchitect/WebGLPreview/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
at Module._extensions..js (node:internal/modules/cjs/loader:1174:10)
at Module.load (node:internal/modules/cjs/loader:998:32)
at Module._load (node:internal/modules/cjs/loader:839:12)
at Module.require (node:internal/modules/cjs/loader:1022:19)
at require (/Users/frankmayer/Documents/Git/WorldArchitect/WebGLPreview/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
at _lmdb (/Users/frankmayer/Documents/Git/WorldArchitect/WebGLPreview/node_modules/#parcel/cache/lib/LMDBCache.js:61:39)
Script error "dev" exited with 1 status
Thanks in advance!
You can override a version using the override option in you package.json.
Read more about this option here: https://docs.npmjs.com/cli/v8/configuring-npm/package-json#overrides
For me, the solution was to add this to my package.json:
"overrides": {
"lmdb": "2.6.0-alpha6",
"#lmdb/lmdb-darwin-arm64": "2.6.0-alpha6",
"#lmdb/lmdb-darwin-x64": "2.6.0-alpha6",
}
This feature is currently (Aug. 2022) not supported by bun!
Yarn does this using resolutions: https://classic.yarnpkg.com/lang/en/docs/selective-version-resolutions
So I tried using Babel to convert my code so that I can run this by node. package.json build is this,
"build": "babel ./public/src -d ./public/lib -w"
When I do npm run build
PS C:\users\leepc\babel\public> npm run build
> babel#1.0.0 build C:\users\leepc\babel
> babel ./public/src -d ./public/lib -w
public\src\blogpost.js -> public\lib\blogpost.js
public\src\main.js -> public\lib\main.js
public\src\publication.js -> public\lib\publication.js
It works right and shows me exactly what I want.
My .babelrc preset is es2015
I run my main.js code and this is happened.
PS C:\users\leepc\babel\public\lib> node main.js
internal/modules/cjs/loader.js:984
throw err;
^
at Function.Module._load
(internal/modules/cjs/loader.js:863:27)
at Module.require
(internal/modules/cjs/loader.js:1043:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous>
(C:\users\leepc\babel\public\lib\main.js:3:17)
at Module._compile
(internal/modules/cjs/loader.js:1157:30) 17)
at Object.Module._extensions..js
(internal/modules/cjs/loader.js:1177:
10)
at Module.load (internal/modules/cjs/loader.js:1001:32)
at Function.Module._load
(internal/modules/cjs/loader.js:900:14)
at Function.executeUserEntryPoint [as runMain]
(internal/modules/run_m
ain.js:74:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\users\\leepc\\babel\\public\\lib\\main.js' ]
}
This is files and folders list in img
My codes are coverted well, but it still got some Module problems. How can I solve this issue? Sorry this is my first time posting question in this website, if I missed some information pls tell me.
edit:
Here is .babelrc
{
"presets": ["es2015"]
}
Okay it turns out, I should combine both of answers above.
First, I have to check whether my import plugin is right or wrong. So I just re-installed it.
npm install babel-plugin-import --save-dev
Make sure not to forget put plugin opitions. In my cases, I use this in .babelrc
{
"presets": ["es2015"],
"plugins": [["import", { "libraryName": "antd" }]]
}
this "plugins": [["import", { "libraryName": "antd" }] line means import js modulary.
And also next stuff, I have to make import path to be corrected.
import { create as newBlogPost } from "blogpost.js";
change this to
import { create as newBlogPost } from "./blogpost.js";
By doing this, now I can get a result that I wanted so far.
PS C:\Users\leePC\babel\public\lib> node main.js
Title: For and against let
By: Kyle Simpson
October 27, 2014
So majorly, 1. Check whether I missed some plugins or packages ( in my cases, I forgot import package ) 2. Make sure to check your import path
Thank you for help guys.
I've been learning Solidity using this course by Stephen Grider and it's been going well until now, where I am trying to deploy my code to the Rinkeby test network.
For reference, I am using Node version 11.15.0 with npm version 6.7.0 with these dependencies:
"dependencies": {
"ganache-cli": "^6.4.3",
"mocha": "^6.1.4",
"nan": "^2.14.0",
"scrypt": "^6.0.3",
"solc": "^0.4.25",
"truffle": "^4.1.15",
"truffle-hdwallet-provider": "0.0.4",
"web3": "^1.0.0-beta.35" }
I have spent hours switching between versions of Node.js, npm, and all sorts of combinations of the dependencies, from the most current versions to the versions specified in the course. While I am getting a multitude of issues, the most prominent two seem to be
(node:32436) V8: C:\Desktop\solidity\inbox\node_modules\solc\soljson.js:3 Invalid asm.js: Invalid member of stdlib
and
C:\Desktop\solidity\inbox\node_modules\solc\soljson.js:1
var Module;if(!Module)Module=(typeof Module!=="undefined"?Module:null)||{};var moduleOverrides={};for(var key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}var ENVIRONMENT_IS_WEB=typeof window==="object";var ENVIRONMENT_IS_WORKER=typeof importScripts==="function";var ENVIRONMENT_IS_NODE=typeof process==="object"&&typeof require==="function"&&!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_WORKER;var ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_NODE&&!ENVIRONMENT_IS_WORKER;if(ENVIRONMENT_IS_NODE){if(!Module["print"])Module["print"]=function print(x){process["stdout"].write(x+"\n")};if(!Module["printErr"])Module["printErr"]=function printErr(x){process["stderr"].write(x+"\n")};var nodeFS=require("fs");var nodePath=require("path");Module["read"]=function read(filename,binary){filename=nodePath["normalize"](filename);var ret=nodeFS["readFileSync"](filename);if(!ret&&filename!=nodePath["resolve"](filename)){filename=path.joi
Error: CONNECTION ERROR: Couldn't connect to node rinkeby.infura.io/v3/acb10732334e4450ba7dc55e618eb70a.
at Object.InvalidConnection (C:\Desktop\solidity\inbox\node_modules\truffle-hdwallet-provider\node_modules\web3\lib\web3\errors.js:28:16)
at HttpProvider.sendAsync (C:\Desktop\solidity\inbox\node_modules\truffle-hdwallet-provider\node_modules\web3\lib\web3\httpprovider.js:129:25)
at Web3Subprovider.handleRequest (C:\Desktop\solidity\inbox\node_modules\web3-provider-engine\subproviders\web3.js:13:17)
at next (C:\Desktop\solidity\inbox\node_modules\web3-provider-engine\index.js:95:18)
at FilterSubprovider.handleRequest (C:\Desktop\solidity\inbox\node_modules\web3-provider-engine\subproviders\filters.js:87:7)
at next (C:\Desktop\solidity\inbox\node_modules\web3-provider-engine\index.js:95:18)
at HookedWalletSubprovider.handleRequest (C:\Desktop\solidity\inbox\node_modules\web3-provider-engine\subproviders\hooked-wallet.js:109:7)
at next (C:\Desktop\solidity\inbox\node_modules\web3-provider-engine\index.js:95:18)
at Web3ProviderEngine._handleAsync (C:\Desktop\solidity\inbox\node_modules\web3-provider-engine\index.js:82:3)
at Web3ProviderEngine._fetchBlock (C:\Desktop\solidity\inbox\node_modules\web3-provider-engine\index.js:191:8)
at Web3ProviderEngine._fetchLatestBlock (C:\Desktop\solidity\inbox\node_modules\web3-provider-engine\index.js:167:8)
at Web3ProviderEngine._startPolling (C:\Desktop\solidity\inbox\node_modules\web3-provider-engine\index.js:144:8)
at Web3ProviderEngine.start (C:\Desktop\solidity\inbox\node_modules\web3-provider-engine\index.js:38:8)
at new HDWalletProvider (C:\Desktop\solidity\inbox\node_modules\truffle-hdwallet-provider\index.js:46:15)
at Object.<anonymous> (C:\Desktop\solidity\inbox\deploy.js:6:18)
at Module._compile (internal/modules/cjs/loader.js:816:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
at Module.load (internal/modules/cjs/loader.js:685:32)
at Function.Module._load (internal/modules/cjs/loader.js:620:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:877:12)
at internal/main/run_main_module.js:21:11
My question would be are there any fixes for either of these issues based on my code, or is there a simpler way to deploy to the blockchain? Thank you in advance.
Error: CONNECTION ERROR: Couldn't connect to node rinkeby.infura.io/v3/acb10732334e4450ba7dc55e618eb70a.
You probably meant https://rinkeby.infura.io/... (You're missing the https://.)
I am following the same tutorial as the OP. If you are using node v14.15.4 and npm v6.14.10, I would like to confirm that the following package.json solved the issue:
{
"name": "inbox",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha"
},
"author": "",
"license": "ISC",
"dependencies": {
"ganache-cli": "^6.4.3",
"mocha": "^6.1.4",
"solc": "^0.4.25",
"truffle-hdwallet-provider": "0.0.4",
"web3": "^1.0.0-beta.35"
}
}
Then rebuild your dependencies by deleting your node_modules of your project, then run
npm install
There may be a problem with the version of the relevant library file, please run the following command.
npm install solc
My npm version is 7.20.3
In my case, the problem was that in the https://infura.io site dropdown what I selected was MAINNET instead of RINKEBY which is an ethereum test network.
I have a problem with my code I used this code in
app.js:
const mongoose = require('mongoose');
const dotenv = require('dotenv');
dotenv.config()
mongoose.connect(process.env.MONGO_URL)
.then(() => console.log("DB connected!"));
mongoose.connection.on('error',function(err){
console.log("The error is: ");
});
env.txt:
MONGO_URL=mongodb+srv://blur:blur#nodeapi-pfnvf8.mongodb.net/test?retryWrites=true
PORT:8080
and for some reason it's giving me this weird error:
throw new MongooseError('The `uri` parameter to `openUri()` must be a ' +
^ MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.
at new MongooseError (C:\Users\razei\Desktop\Recat\project2\node_modules\mongoose\lib\error\mongooseError.js:14:11)
at NativeConnection.Connection.openUri (C:\Users\razei\Desktop\Recat\project2\node_modules\mongoose\lib\connection.js:465:11)
at Mongoose.connect (C:\Users\razei\Desktop\Recat\project2\node_modules\mongoose\lib\index.js:289:15)
at Object.<anonymous> (C:\Users\razei\Desktop\Recat\project2\ap.js:9:10)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3) [nodemon] app crashed - waiting for file changes before starting...
can someone please help me I read a few posts but none of them helped
This also occurs when you aren't saving your .env file in the root folder.
Save your env file as .env not env.txt and make sure it's in your root folder as well & see if that works! Also MONGO_URI is the traditional naming convention but that shouldn't matter.
mongoose
.connect(process.env.MONGO_URL, {
useNewUrlParser: true,
useCreateIndex: true,
useUnifiedTopology: true
})
.then(() => {
console.log('Connected to Mongo!');
})
.catch((err) => {
console.error('Error connecting to Mongo', err);
});
Additionally you can simplify your 2 require statements above with the lines below and you should call this as soon as possible:
require('dotenv').config();
const mongoose = require('mongoose')
Require dotenv like this. It worked for me
require('dotenv').config();
first of all, the env file should be saved as .env not env.txt, .txt is an extension for text files.
Also, I don't think you have named your project 'test' so make sure to change it to your current project name.
If you still get an error, do not use environment variables instead add the whole mongodb path inside mongoose.connect() in double or single quotes.
mongoose.connect(process.env.mongodb, {
useUnifiedTopology: true,
useNewUrlParser: true,
useCreateIndex: true,
});
I too was getting the same errors, It was crashing due to the environment variable MONGODB_URI not being set and running heroku config returned with no variables in the cli.
The fix was running : heroku addons:create mongolab:sandbox
If heroku push origin master is needed, then heroku config should now show your .env variable.
The error comes when we put our database credentials in .env file and in main file of server we create connection before .env file, instead we should create connection after requiring .env file.
I encountered this error as well, The first thing you need to do is to place your .env file in the "ROOT FOLDER". This will solve your issue.
was having the same error.. :
This also worked for me..
require('dotenv').config();
checkout this post for more info : https://dev.to/aritik/connecting-to-mongodb-using-mongoose-3akh
Make sure the root folder is where config.env is created and that the right path is specified for # app.js => dotenv.config(path: "./config.env").
dotenv.config({ path: "./config.env" });
const dotenv = require('dotenv');
dotenv.config({path:'config.env'});
const mongoose = require('mongoose');
mongoose.connect(process.env.MONGO_URI, {
useUnifiedTopology: true,
useNewUrlParser: true
});
I fixed that myApp.js file code
config.env file code
package.json file
"name": "fcc-mongo-mongoose-challenges",
"version": "0.0.1",
"description": "A boilerplate project",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"body-parser": "^1.15.2",
"dotenv": "^8.2.0",
"express": "^4.12.4",
"mongodb": "^4.12.1",
"mongoose": "^5.11.15"
},
"repository": {
"type": "git",
"url": "https://github.com/freeCodeCamp/boilerplate-mongomongoose.git"
},
"keywords": [
"node",
"mongoose",
"express"
],
"license": "MIT"
}
Please check above two screenshots to solve this problem
Hope this will be help to anyone
i tried to generate reports by using "'protractor-jasmine2-html-reporter'", but i'm getting module not found exception with error code 5..i tried the somany solutions gathered from stack overflow, but it is not worked. can somebody please help me in this.
Config.js
var Jasmine2HtmlReporter=require('protractor-jasmine2-html-reporter');
exports.config = {
directConnect : true,
capabilities:{
'browserName':'chrome'
},
framework: 'jasmine2',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['ProtractorTest/PageObjectMain.js'],
jasmineNodeOpts:{
defaultTimeoutInterval : 30000
},
onPreapre:function(){
jasmine.getEnv().addReporter(new Jasmine2HtmlReporter({
savePath:"./test-results/report"
}));
},
}
Error log
[14:54:53] E/configParser - Error code: 105
[14:54:53] E/configParser - Error message: failed loading configuration file ReportConfig.js
[14:54:53] E/configParser - Error: Cannot find module 'protractor-jasmine2-html-reporter'
at Function.Module._resolveFilename (module.js:538:15)
at Function.Module._load (module.js:468:25)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (H:\workspace\Protractor_tutorials\ReportConfig.js:1:88)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
and my 'Package.Json' not have any details about the report files.. so if that is the problem, please help me to how to configure those in json file.
There are few things you have to make sure while using Protractor Reporters
1.in my case, in the time creating variable for reporter instead of directly passing Reporter name try to pass the full path of Reporter module.. may this will work
Eg :
var Jasmine2HtmlReporter=require('C:/......./npm-modules/protractor-jasmine2-html-reporter');
2.make sure you running the Correct Configuration file having .js extension.
Installing without save-devworked for me .
Installed globally
npm install -g protractor-jasmine2-html-reporter
Run below command to link protractor and jasmine2-html-reporter to aovid report not generating issue. Please see Girish Sortur's answer in How to create Protractor reports with Jasmine2
npm link protractor-jasmine2-html-reporter
Also add this import with path to exact node module to avoid the error in windows 10
var Jasmine2HtmlReporter = require('C:/Users/sam/AppData/Roaming/npm/node_modules/protractor-jasmine2-html-reporter');
Full conifg,js that worked for me in windows 10 as per below.
//protractor jasminreporterconfig.js
//Add this import with path to exact node module to avoid the error
var Jasmine2HtmlReporter = require('C:/Users/sam/AppData/Roaming/npm/node_modules/protractor-jasmine2-html-reporter');
exports.config = {
framework: 'jasmine',
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: [ "--start-maximized" ]
}
},
onPrepare: function() {
jasmine.getEnv().addReporter(
new Jasmine2HtmlReporter({
takeScreenshots: true,// By default this is enabled Default is true
takeScreenshotsOnlyOnFailures: false, // Default is false (So screenshots are always generated)
cleanDestination: true, // if false, will not delete the reports or screenshots before each test run.Default is true
showPassed: true,//default is true This option, if false, will show only failures.
fileName: 'MyRepoDemo', //We can give a prefered file name .
savePath: 'myproreports',//Reports location it will automatically generated
screenshotsFolder: 'screenshotsloc' //Screenshot location it will create a folder inside myproreports
})
);
},
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['src/com/sam/scriptjs/nonangularstackscript.js']
}
It looks like You haven't installed protractor-jasmine2-html-reporter
Go to folder where packages are installed (node_modules folder) and run:
npm install protractor-jasmine2-html-reporter
Try to check where the node_modules directory is present by running npm audit and which npm commands. The main thing is path where node_modules is installed should be traced and the new module like npm install protractor-jasmine2-html-reporter can be installed in that path