![](/img/trans.png)
[英]Node.js SyntaxError: Invalid or unexpected token (but its weird)
[英]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.