javascript - 1 :1 error Parsing error: Unexpected character '�'

标签 javascript npm eslint

我是 JavaScript 新手,如果这是一个愚蠢的问题,我很抱歉。我尝试运行 Firebase 部署,但最终出现此错误消息

  1:1  error  Parsing error: Unexpected character '�'

✖ 1 problem (1 error, 0 warnings)

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! functions@1.0.0 lint: `eslint .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the functions@1.0.0 lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Tino\AppData\Roaming\npm-cache\_logs\2018-07-15T14_22_52_268Z-debug.log

Error: functions predeploy error: Command terminated with non-zero exit code1

我的index.js看起来像这样

const functions = require('firebase-functions');
// replaces keywords with emoji in the "text" key of messages
// pushed to /messages
exports.emojify =
    functions.database.ref('/messages/{pushId}/text')
    .onWrite(event => {
        // Database write events include new, modified, or deleted
        // database nodes. All three types of events at the specific
        // database path trigger this cloud function.
        // For this function we only want to emojify new database nodes,
        // so we'll first check to exit out of the function early if
        // this isn't a new message.

        // !event.data.val() is a deleted event
        // event.data.previous.val() is a modified event
        if (!event.data.val() || event.data.previous.val()) {
            console.log("not a new write event");
            return;
        }

        // Now we begin the emoji transformation
        console.log("emojifying!");

        // Get the value from the 'text' key of the message
        const originalText = event.data.val();
        const emojifiedText = emojifyText(originalText);

        // Return a JavaScript Promise to update the database node
        return event.data.ref.set(emojifiedText);
    });

// Returns text with keywords replaced by emoji
// Replacing with the regular expression /.../ig does a case-insensitive
// search (i flag) for all occurrences (g flag) in the string
function emojifyText(text) {
    var emojifiedText = text;
    emojifiedText = emojifiedText.replace(/\blol\b/ig, ":D");
    emojifiedText = emojifiedText.replace(/\bcat\b/ig, ":D(cat)");
    return emojifiedText;
}

C:\Users\Tino\AppData\Roaming\npm-cache_logs\2018-07-15T14_22_52_268Z-debug.log 的完整日志如下所示

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   '--prefix',
1 verbose cli   'C:\\Users\\Tino\\Desktop\\FriendlyChatFunctions\\functions',
1 verbose cli   'run',
1 verbose cli   'lint' ]
2 info using npm@5.6.0
3 info using node@v8.11.3
4 verbose run-script [ 'prelint', 'lint', 'postlint' ]
5 info lifecycle functions@1.0.0~prelint: functions@1.0.0
6 info lifecycle functions@1.0.0~lint: functions@1.0.0
7 verbose lifecycle functions@1.0.0~lint: unsafe-perm in lifecycle true
8 verbose lifecycle functions@1.0.0~lint: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\Tino\Desktop\FriendlyChatFunctions\functions\node_modules\.bin;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\sqlite;C:\Users\Tino\putty\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Brackets\command;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\nodejs\;C:\Program Files\Java\jre-9.0.4\bin;C:\Users\Tino\AppData\Local\Microsoft\WindowsApps;C:\Users\Tino\AppData\Roaming\npm
9 verbose lifecycle functions@1.0.0~lint: CWD: C:\Users\Tino\Desktop\FriendlyChatFunctions\functions
10 silly lifecycle functions@1.0.0~lint: Args: [ '/d /s /c', 'eslint .' ]
11 silly lifecycle functions@1.0.0~lint: Returned: code: 1  signal: null
12 info lifecycle functions@1.0.0~lint: Failed to exec lint script
13 verbose stack Error: functions@1.0.0 lint: `eslint .`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:285:16)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at EventEmitter.emit (events.js:214:7)
13 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at ChildProcess.emit (events.js:214:7)
13 verbose stack     at maybeClose (internal/child_process.js:925:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
14 verbose pkgid functions@1.0.0
15 verbose cwd C:\Users\Tino\Desktop\FriendlyChatFunctions
16 verbose Windows_NT 10.0.17134
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "--prefix" "C:\\Users\\Tino\\Desktop\\FriendlyChatFunctions\\functions" "run" "lint"
18 verbose node v8.11.3
19 verbose npm  v5.6.0
20 error code ELIFECYCLE
21 error errno 1
22 error functions@1.0.0 lint: `eslint .`
22 error Exit status 1
23 error Failed at the functions@1.0.0 lint script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

代码是从教程(2年前)复制粘贴的,所以我不知道可能出了什么问题。

最佳答案

它看起来像文件开头的UTF-8 BOM

如果您有 Notepad++ ,可以通过单击“编码”->“转换为无 BOM 的 UTF-8”来删除它:

enter image description here

Read more about BOM

关于javascript - 1 :1 error Parsing error: Unexpected character '�' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51349355/

相关文章:

npm - yarn 和 npm 在实践中可以互换吗?

node.js - 需要 EventEmitter 与 Node 和 React-Native 兼容

javascript - 在 DOM 对象上设置属性时如何避免无参数重新分配

javascript - 如何强制调用 React.js Hook 的顺序

javascript - 在 React 中显示/隐藏子组件

javascript - 随机唯一数字的大小数组

node.js - 为什么不在 package.json 文件中指定特定的包版本?那么我们就不需要package-lock.json

javascript - 函数目标 ID 范围

javascript - 多选复选框下拉

eslint - slim 的更漂亮/eslint