I'm confused with why is this bot now functioning, I think it's as I don't have a "index.js" I use "main.js" How can I some how switch from "main.js" to "index.js"?
I'll add all the main codes that may help you spot an error :D
Here is the code in "main.js":
const { Client, Collection, Intents } = require('discord.js');
const client = new Client({ disableMentions: 'everyone', partials:
['MESSAGE', 'CHANNEL', 'REACTION'], ws: { intents: Intents.ALL } });
client.commands = new Collection();
client.aliases = new Collection();
['command', 'event'].forEach(handler => {
require(`./handlers/${handler}`)(client);
});
client.login(process.env.BOT_TOKEN);
Error:
internal/fs/utils.js:269
throw err;
^
Error: ENOENT: no such file or directory, open '/home/runner/DwaCraft-Ticket-bot/index.js'
at Object.openSync (fs.js:462:3)
at Object.readFileSync (fs.js:364:35)
at Object.<anonymous> (/run_dir/interp.js:195:19)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at internal/main/run_main_module.js:17:47 {
errno: -2,
syscall: 'open',
code: 'ENOENT',
path: '/home/runner/DwaCraft-Ticket-bot/index.js'
}
repl process died unexpectedly: exit status 1
Package.json:
{
"name": "ticket-bot",
"version": "1.0.0",
"description": "A simple ticket bot",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node main.js"
},
"author": "hamoodi",
"license": "ISC",
"dependencies": {
"better": "^0.1.0",
"cpu-stat": "^2.0.1",
"discord.js": "^12.5.3",
"dotenv": "^8.6.0",
"express": "^4.17.1",
"moment": "^2.29.1",
"os": "^0.1.2",
"sourcebin_js": "0.0.3-ignore"
}
}
Files:
https://i.stack.imgur.com/FptiD.png
As below link said you can Create a .replit file, and inside it put
run="node [file].js"
and replace [file] to main.
https://replit.com/talk/ask/Is-it-possible-to-changedeleted-indexjs/43264
Change the name file from main.js to index.js in "scripts" => "start" in package.json file and hit npm start. Remember to run the script from the folder where the main.js file is located, and rename files!
{
"name": "ticket-bot",
"version": "1.0.0",
"description": "A simple ticket bot",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"author": "hamoodi",
"license": "ISC",
"dependencies": {
"better": "^0.1.0",
"cpu-stat": "^2.0.1",
"discord.js": "^12.5.3",
"dotenv": "^8.6.0",
"express": "^4.17.1",
"moment": "^2.29.1",
"os": "^0.1.2",
"sourcebin_js": "0.0.3-ignore"
}
}
Related
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?
I'm trying to get more familiar with modern javascript and am following a tutorial. Early setup includes running a file from another file. I have a server.js file with a simple 'import './config'; command. As a test that repo setup is correct, I should be able to run 'babel server.js'. But I keep returning the error shown below. How do I troubleshoot so that I can successfully run babel commands?
myName#SE-C02YNKJ9LVCF in ~/Linkedin_Learning/modern_javascript_app_example (main) > babel src/server.js
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '#babel/plugin-proposal-class' imported from /Users/myName/Linkedin_Learning/modern_javascript_app_example/babel-virtual-resolve-base.js
at new NodeError (/usr/local/lib/node_modules/#babel/cli/node_modules/#babel/core/lib/vendor/import-meta-resolve.js:2795:5)
at packageResolve (/usr/local/lib/node_modules/#babel/cli/node_modules/#babel/core/lib/vendor/import-meta-resolve.js:3451:9)
at moduleResolve (/usr/local/lib/node_modules/#babel/cli/node_modules/#babel/core/lib/vendor/import-meta-resolve.js:3485:18)
at defaultResolve (/usr/local/lib/node_modules/#babel/cli/node_modules/#babel/core/lib/vendor/import-meta-resolve.js:3524:13)
at /usr/local/lib/node_modules/#babel/cli/node_modules/#babel/core/lib/vendor/import-meta-resolve.js:3547:14
at Generator.next (<anonymous>)
at asyncGeneratorStep (/usr/local/lib/node_modules/#babel/cli/node_modules/#babel/core/lib/vendor/import-meta-resolve.js:63:103)
at _next (/usr/local/lib/node_modules/#babel/cli/node_modules/#babel/core/lib/vendor/import-meta-resolve.js:65:194)
at /usr/local/lib/node_modules/#babel/cli/node_modules/#babel/core/lib/vendor/import-meta-resolve.js:65:364
at new Promise (<anonymous>) {
code: 'ERR_MODULE_NOT_FOUND'
}
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '#babel/plugin-proposal-class' imported from /Users/myName/Linkedin_Learning/modern_javascript_app_example/babel-virtual-resolve-base.js
at new NodeError (/usr/local/lib/node_modules/#babel/cli/node_modules/#babel/core/lib/vendor/import-meta-resolve.js:2795:5)
at packageResolve (/usr/local/lib/node_modules/#babel/cli/node_modules/#babel/core/lib/vendor/import-meta-resolve.js:3451:9)
at moduleResolve (/usr/local/lib/node_modules/#babel/cli/node_modules/#babel/core/lib/vendor/import-meta-resolve.js:3485:18)
at defaultResolve (/usr/local/lib/node_modules/#babel/cli/node_modules/#babel/core/lib/vendor/import-meta-resolve.js:3524:13)
at /usr/local/lib/node_modules/#babel/cli/node_modules/#babel/core/lib/vendor/import-meta-resolve.js:3547:14
at Generator.next (<anonymous>)
at asyncGeneratorStep (/usr/local/lib/node_modules/#babel/cli/node_modules/#babel/core/lib/vendor/import-meta-resolve.js:63:103)
at _next (/usr/local/lib/node_modules/#babel/cli/node_modules/#babel/core/lib/vendor/import-meta-resolve.js:65:194)
at /usr/local/lib/node_modules/#babel/cli/node_modules/#babel/core/lib/vendor/import-meta-resolve.js:65:364
at new Promise (<anonymous>) {
code: 'ERR_MODULE_NOT_FOUND'
Things I've tried so far
as per tutorial, tried updating my bash_profile w/ 'export PATH=$PATH:./node_modules/.bin'
tried setting it in global PATH variable
setting all devDependencies in package.json file that mention #babel to consistent version.
After updating package.json file, new error is below:
ReferenceError: module is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/Users/robertgorowsky/Linkedin_Learning/modern_javascript_app_example/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///Users/myName/Linkedin_Learning/modern_javascript_app_example/babel.config.js:1:1
at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:541:24)
at async importModuleDynamicallyWrapper (node:internal/vm/module:438:15)
When I run babel --version, it returns '7.19.3 (#babel/core 7.19.3)' matching package.json file.
contents of files:
content.js
console.log('config test')
server.js
import './config';
package.json
{
"name": "modern_javascript_app_example",
"version": "1.0.0",
"description": "Learning fullstack JavaScript Dev with MongoDB, Node.js, React.js",
"main": "index.js",
"type": "module", //added this line after first answer
"scripts": {
"start": "nodemon --exec babel-node server.js --ignore public/",
"dev": "webpack -wd"
},
"repository": {
"type": "git",
"url": "git+https://github.com/rgorowsky/modern_javascript_app_example.git"
},
"author": "",
"license": "GPL-3.0",
"bugs": {
"url": "https://github.com/rgorowsky/modern_javascript_app_example/issues"
},
"homepage": "https://github.com/rgorowsky/modern_javascript_app_example#readme",
"dependencies": {
"express": "^4.18.1",
"mongodb": "^4.10.0",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"#babel/node": "^7.19.1",
"#babel/core": "^7.19.3",
"#babel/plugin-proposal-class-properties": "^7.18.6",
"#babel/preset-env": "^7.19.3",
"#babel/preset-react": "^7.18.6",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.2.5",
"eslint": "^8.23.1",
"eslint-plugin-react": "^7.31.8",
"nodemon": "^2.0.20",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
}
}
webpack.config.js
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve('public'),
filename: 'bundle.js',
},
module: {
rules: [
{
test: /|.js$/,
exclude: /.node_modules/,
use: {
loader: 'babel-loader',
},
},
],
},
};
babel.config.js
module.exports = {
presets: ['#babel/react', '#babel/env'],
plugins: ['#babel/plugin-proposal-class-properties'],
};
A picture of my repo file structure for reference:
please do the following step
add "type": "module" in package.json
{
"name": "modern_javascript_app_example",
"version": "1.0.0",
"description": "Learning ...",
"main": "index.js",
"type": "module",
"scripts": {
and use import './content.js'; not import './config'; in serer.js file
I'm getting 502 responses when trying to simply add const solc = require('solc') to a deployed AWS lambda function. I've successfully used used a variety of different node packages in this lambda function with no problems. Also, I've used the solc module locally and in other contexts with no problems. What can I do to get to successfully require the solc module?
Lambda function:
const solc = require('solc')
module.exports = {
constructContractTx: async(event, web3) => {
// compileContract(event)
return {
body: 'testing',
status: 200
}
}
}
package.json:
{
"name": "...",
"version": "1.0.0",
"description": "...",
"main": "app.js",
"repository": "...",
"author": "Chris Dougherty",
"license": "MIT",
"dependencies": {
"#alch/alchemy-web3": "^1.1.9",
"#ethereumjs/common": "^2.6.2",
"#ethereumjs/tx": "^3.5.0",
"axios": "0.21.1",
"dotenv": "^15.0.0",
"faunadb": "^4.4.1",
"fs": "^0.0.1-security",
"path": "^0.12.7",
"solc": "0.8.10",
"web3": "1.5.2"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
}
}
I'm trying to run the command below but unfortunately I run into an error.
C:\Users\usver\Desktop\git test\git\Bootstrap4\conFusion>gulp
I got assertion error after running the above command. I reinstalled gulp and npm once again but got the same error.
My node version-v10.15.0
gulp version-
CLI version 2.0.1
Local version 4.0.2
assert.js:350
throw err;
^
AssertionError [ERR_ASSERTION]: Task function must be specified
at Gulp.set [as _setTask] (C:\Users\usver\Desktop\git test\git\Bootstrap4\conFusion\node_modules\undertaker\lib\set-task.js:10:3)
at Gulp.task (C:\Users\usver\Desktop\git test\git\Bootstrap4\conFusion\node_modules\undertaker\lib\task.js:13:8)
at Object.<anonymous> (C:\Users\usver\Desktop\git test\git\Bootstrap4\conFusion\gulpfile.js:30:6)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
I m Using Windows 10 Operating System and VS Code as an editor.
gulp.js file:
'use strict';
var gulp=require('gulp'),
sass=require('gulp-sass'),
browserSync=require('browser-sync');
gulp.task('sass',function(){
return gulp.src('./css/*.scss')
.pipe(sass().on('error',sass.logerror))
.pipe(gulp.dest('./css'));
});
gulp.task('sass:watch',function(){
gulp.watch('./css/*.scss',['sass']);
});
gulp.task('browser-sync',function(){
var files=[
'./*.html',
'./css/*.css',
'./js/*.js',
'./img/*.{png,jpg,gif}'
];
browserSync.init(files,{
server:{
baseDir:'./'
}
});
});
gulp.task('default',['browser-sync'],function(){
gulp.start('sass:watch');
});`
package.json file
{
"name": "confusion",
"version": "1.0.0",
"description": "This is a website for Ristorante Con Fusion",
"main": "index.html",
"scripts": {
"start": "npm run watch:all",
"test": "echo \"Error: no test specified\" && exit 1",
"lite": "lite-server",
"scss": "node-sass -o css/ css/",
"watch:scss": "onchange \"css/*.scss\" --npm run scss",
"watch:all": "parallelshell \"npm run watch:scss\" 'npm run lite'",
"clean": "rimraf dist",
"copyfonts": "copyfiles -f node_modules/font-awesome/fonts/* dist/fonts",
"imagemin": "imagemin img/* -o dist/img",
"usemin": "usemin contactus.html -d dist --htmlmin -o dist/contactus.html && usemin aboutus.html -d dist --htmlmin -o dist/aboutus.html && usemin index.html -d dist --htmlmin -o dist/index.html",
"build": "npm run clean && npm run copyfonts && npm run imagemin && npm run usemin"
},
"author": "",
"license": "ISC",
"devDependencies": {
"browser-sync": "^2.26.7",
"cssmin": "^0.4.3",
"del": "^3.0.0",
"grunt-browser-sync": "^2.2.0",
"grunt-cli": "^1.2.0",
"grunt-contrib-clean": "^1.1.0",
"grunt-contrib-concat": "^1.0.1",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-cssmin": "^2.2.1",
"grunt-contrib-htmlmin": "^2.4.0",
"grunt-contrib-imagemin": "^3.1.0",
"grunt-contrib-uglify": "^3.3.0",
"grunt-contrib-watch": "^1.1.0",
"grunt-filerev": "^2.3.1",
"grunt-sass": "^2.1.0",
"grunt-usemin": "^3.1.1",
"gulp": "^4.0.2",
"gulp-sass": "^3.1.0",
"htmlmin": "0.0.7",
"jit-grunt": "^0.10.0",
"lite-server": "^2.3.0",
"node-sass": "^4.12.0",
"onchange": "^6.0.0",
"parallelshell": "^3.0.2",
"rimraf": "^2.6.2",
"time-grunt": "^1.4.0",
"uglifyjs": "^2.4.11",
"usemin-cli": "^0.5.1"
},
"dependencies": {
"bootstrap": "^4.3.1",
"bootstrap-social": "^5.1.1",
"font-awesome": "^4.7.0",
"grunt": "^1.0.4",
"jquery": "^3.4.1",
"popper.js": "^1.12.9"
}
}
I've include gulp.js and package.json file.
You are using gulp3 syntax in a gulp4 file.
Search your error message Task function must be specified and you will get lots of hits.
Change these lines:
gulp.task('sass:watch',function(){
// gulp.watch('./css/*.scss',['sass']);
gulp.watch('./css/*.scss', gulp.series('sass'));
// gulp.watch('./css/*.scss', 'sass'); // should work too
});
and
// gulp.task('default',['browser-sync'],function(){
//gulp.start('sass:watch');
// });
to
gulp.task('default', gulp.series('browser-sync', 'sass:watch'));
It looks like you were working off of an old gulp3 tutorial but look for some migration guides from gulp3 to gulp4 instead.
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).