[英]node.js SyntaxError: Invalid or unexpected token
I have downloaded and installed node.js from https://nodejs.org/en/ .我已经从https://nodejs.org/en/下载并安装了 node.js。 I want to run a js file:
我想运行一个js文件:
console.log('hello');
I run node app.js我运行节点 app.js
And get a syntax error:并得到一个语法错误:
SyntaxError: Invalid or unexpected token
[90m at Module._compile (internal/modules/cjs/loader.js:895:18)[39m
[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)[39m
[90m at Module.load (internal/modules/cjs/loader.js:815:32)[39m
[90m at Function.Module._load (internal/modules/cjs/loader.js:727:14)[39m
[90m at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)[39m
[90m at internal/main/run_main_module.js:17:11[39m
My OS Info:我的操作系统信息:
Version: 10.0.18362
BuildNumber: 18362
OSArchitecture: 32-bit
node.js v12.13.1 node.js v12.13.1
Did you copy some unicode characters from word or something?您是否从 word 或其他内容中复制了一些 unicode 字符?
try retyping the console.log('hello')
Something like this has happened to me before, when I copied some code from a word document.尝试重新输入
console.log('hello')
以前我从word 文档中复制一些代码时发生过这样的事情。
The problem was that I created the file by redirecting output from echo command in powershell.问题是我通过在 powershell 中重定向 echo 命令的输出来创建文件。 It had UTF-16 LE encoding, should be UTF-8
它有 UTF-16 LE 编码,应该是 UTF-8
Had the same issue for hours, echo const http=require('http')
>> index.js
.几个小时都有同样的问题,
echo const http=require('http')
>> index.js
。 Solved解决了
Still, nothing!依然没有! It wont work!
它不会工作!
Code:
// Require the necessary discord.js classes
const { Client, Intents } = require('discord.js');
const config = require('./config.json')
// Create a new client instance
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
// When the client is ready, run this code (only once)
client.once('ready', () => {
console.log('Ready!');
console.log ("My new first bot is ready and is launched! Yay!")
});
// Login to Discord with your client's token
client.login(config.token)
// CREATE COMMANDS!!!
client.on("messageCreate", async (message) => {
let prefix = "$"
const prefixRegex = new RegExp(`^(<@!?${client.user.id}>|${escapeRegex(prefix)})\\s*`);
if(prefixRegex.test(message.content)) {
const [, matchedPrefix] = message.content.match(prefixRegex);
let args = message.content.slice(matchedPrefix.length).trim().split(/ +/);
let cmd = args.shift()?.toLowerCase();
if(cmd == "test") {
return message.channel.send("I am Working!")
})
Error:
SyntaxError: Unexpected token ')'
at Object.compileFunction (node:vm:360:18)
at wrapSafe (node:internal/modules/cjs/loader:1055:15)
at Module._compile (node:internal/modules/cjs/loader:1090:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47
Idk what I did wrong... Idk 我做错了什么...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.