Error 1:1 Encountered parsing issue: Unanticipated character ''

I'm still getting acquainted with JavaScript, so please bear with me if this question seems a bit basic. I've been attempting to execute Firebase deploy but keep encountering this error message:

  1:1  error  Parsing error: Unexpected character ''

✖ 1 problem (1 error, 0 warnings)

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! lint: `eslint .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the 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

This is how my index.js file looks like:

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
function emojifyText(text) {
    var emojifiedText = text;
    emojifiedText = emojifiedText.replace(/\blol\b/ig, ":D");
    emojifiedText = emojifiedText.replace(/\bcat\b/ig, ":D(cat)");
    return emojifiedText;
}

The detailed log for C:\Users\Tino\AppData\Roaming\npm-cache_logs\2018-07-15T14_22_52_268Z-debug.log is as follows:

... (log details here)

The code has been borrowed from a tutorial that's about 2 years old, so I'm unsure what might be causing this issue.

Answer №1

It appears that your file may have a UTF-8 BOM at the beginning.

If you are using notepad++, you can remove it by going to "Encoding" -> "Convert to UTF-8 without BOM":

https://i.sstatic.net/lkZGA.png

Learn more about UTF-8 BOM

Answer №2

My encoding was originally set to UTF-16LE instead of UTF-8. To switch it back on VS Code, simply select the option for UTF-16LE, choose the "Save with encoding" function, and then reselect UTF-8

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to modify a variable in the Config.json using a Discord.js command

Lately, I enhanced my bot's functionality by allowing it to retrieve the color for embeds from a file specified in my config.json. All I need to do is modify something like: "embedcolor": "00A950" to "embedcolor": "0 ...

Tips for installing npm packages using a python script in the same directory as my script

The desired file structure should resemble this: test.py node_modules (Folder containing installed npm modules) Here is the attempted solution: import subprocess import os dir_path = os.path.dirname(os.path.realpath(__file__)) # Retrieve the directory ...

The function io.sockets.in(roomName) does not seem to be properly listening for myEvent after joining the

I am looking to dynamically create rooms based on incoming requests from the front end. I found guidance in this gist. My goal is for a specific room to listen for events and communicate with other members within that room. However, I am experiencing an i ...

Encountering a problem during the installation of Npm Multer for file uploads in node.js has been quite the challenge

npm ALERT read-shrinkwrap The version of npm is only compatible with lockfileVersion@1, however, the package-lock.json was generated for lockfileVersion@2. Attempting to proceed nonetheless! npm ALERT <a href="/cdn-cgi/l/email-protection" class="__cf_em ...

What steps are involved in creating a user form using react and redux?

Upon the initial loading of my application, it retrieves user data from the server and displays the information in an AppBar (material-ui): displayProfileLink () { const {user} = this.props; if (!user.name) { return <CircularProgress styl ...

Leveraging jQuery Ajax and MySQL to generate dynamic HTML content

I'm in the process of creating a unique photo gallery that utilizes dynamic features. Instead of relying on constant HTML/PHP refreshing for updates, I am incorporating jQuery to handle dynamic MYSQL queries. As a beginner, I've managed to creat ...

Embedded tweets may occasionally lose their borders when viewed on various web browsers

My goal is to showcase a collection of responsive embedded tweets in rows of 2. Here are the key elements of the code that have enabled me to achieve this: HTML <div id="tweets"></div> <script src="https://platform.twitter.com/widgets.js" ...

Addressing ESLint and TypeScript Issues in Vue.js with Pinia: A comprehensive guide

Experiencing difficulties with Vue.js + Pinia and need assistance to resolve these issues. Error: 'state:' is defined but never used. Here is the snippet of code located in @/stores/user.ts. import { defineStore } from 'pinia' export ...

Transferring HTML content from AngularJS to PHP

I've been attempting to transmit HTML data from Angular to PHPMailer in the form of a JSON object and then decoding it on PHP. However, I'm facing issues where only elements like h1, h2.... p can be sent successfully. When I try to use div / a ta ...

Transmitting Filter Choices as an Object for Retrieving Multiple Values within an Angular Application

In my Angular application, I have a function that takes user selections for various filter types and sends a request to the API to retrieve filtered data based on those selections. Each filter type returns values in an array format, allowing users to selec ...

What is the best way to retrieve a response from a PHP file as an array through Ajax?

Seeking assistance in retrieving a complete address by entering the postal code in an HTML form textbox and clicking a button. The setup involves two files - one containing the ajax function and the other housing the PHP code. Uncertainty looms over whethe ...

Is it possible to retrieve a variable from code.gs and pass it to my html file?

I had originally set up an automated email system to trigger once a certain condition was met, which I successfully implemented. However, I now want to enhance the email by including a more structured format and embedding an image from Google Drive. While ...

Press on the div to reveal its content at the clicked position

Hello, I have a query that I need help with. I currently have a basic table with buttons in columns that act as filters. When you click on one of these buttons, it opens up a form. https://i.sstatic.net/nuEpq.png What I am trying to achieve is to make t ...

Is there a way to perform nested association counting in Sequelize?

Exploring ways to tally product reviews within nested associations using a specific query. const user = await User.findOne({ where: { id: req.query.user }, attributes: ["id", "name"], include: [ { model: Category, as: "interest ...

What is the best method to extract the URL from an iframe div element using jQuery or JavaScript?

I have a dynamic way of getting my URL source, as shown in the code below. Is it possible to retrieve the URL from within the gettingiframe div, which is located inside an iframe? Below is the code snippet: <div id="gettingiframe"> <iframe sr ...

The worth of the scope is evident, yet it remains undefined when trying to access it

Currently, I am in the process of developing an AngularJS directive. However, I have encountered an issue where a scope variable appears to be undefined when attempting to access it. Interestingly, upon printing out the scope, it is evident that the variab ...

If someone installs our chat widget on their website using an <iframe> script, I would like the widget to be deactivated when our website is experiencing downtime

We utilize an iframe to create our Chat Widget. One issue we face is that when our main website is down, it causes errors on client websites where the widget is embedded. I am looking for a way to automatically disable the "Chat widget" when our website ...

What steps can be taken to ensure that events are triggered on the correct DIV element?

I am considering two different HTML structures for my project: <div id="threeJSContainer"> </div> <div id="UIControls"> <div ng-include src="'scripts/angular/UI.html'"></div> </div> When using the first c ...

What is the most efficient way to include multiple JavaScript functions without requiring document.ready() for each individual function?

I currently have functional code that looks like this: $(document).ready(function() { $("#num1").click(function() { $("li.elementsA").addClass("alerty"); return false }); }); $(document).ready(function() { $("#num2").click(function() { $(" ...

Footer Cell isn't showing up as expected within *ngFor loop in Mat-Table

I'm having trouble displaying the total sum at the bottom of my table. Despite following the steps outlined in the documentation exactly, it still doesn't seem to be working for me. Below you can find the code from my template: <table mat-t ...