繁体   English   中英

node.js SyntaxError:无效或意外令牌

[英]node.js SyntaxError: Invalid or unexpected token

我已经从https://nodejs.org/en/下载并安装了 node.js。 我想运行一个js文件:

console.log('hello');

我运行节点 app.js

并得到一个语法错误:

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

我的操作系统信息:

Version: 10.0.18362
BuildNumber: 18362
OSArchitecture: 32-bit

node.js v12.13.1

您是否从 word 或其他内容中复制了一些 unicode 字符?

尝试重新输入console.log('hello')以前我从word 文档中复制一些代码时发生过这样的事情。

问题是我通过在 powershell 中重定向 echo 命令的输出来创建文件。 它有 UTF-16 LE 编码,应该是 UTF-8

几个小时都有同样的问题, echo const http=require('http') >> index.js 解决了

依然没有! 它不会工作!

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 我做错了什么...

图片

如果你在照片上掠夺。 你可以看到错误出现在 R21 上。 您正在尝试使用 ) 而不是 } 从 r14 关闭 if

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM