The wasm URL file scheme cannot be loaded as it is not supported

Currently, I am exploring the functionality of sql.js through this resource:

My journey began with their introductory HTML example which seems to be causing a series of errors during execution.

To start off, I installed sql.js using the command: npm install sql.js

After installing sql.js, I transferred the 'dist' folder from the installation into the 'test' directory where the index.html is located.

Following the example code provided, when I attempted to open it in a browser, I was met with an error message stating:

sql-wasm.js:167 Fetch API cannot load file:///C:/dist/sql-wasm.wasm. URL scheme "file" is not supported.

Here's a snippet of the code:

<meta charset="utf8" />
<html>
  <script src='C:\\Users\\Rocko\\Documents\\scripts\\AAOA\\nodetest\\dist\\sql-wasm.js'></script>
  <script>
    config = {
      locateFile: filename => `/dist/${filename}`
    }
    // The `initSqlJs` function is globally provided by all of the main dist files if loaded in the browser.
    // We must specify this locateFile function if we are loading a wasm file from anywhere other than the current html page's folder.
    initSqlJs(config).then(function(SQL){
      //Create the database
      const db = new SQL.Database();
      // Run a query without reading the results
      db.run("CREATE TABLE test (col1, col2);");
      // Insert two rows: (1,111) and (2,222)
      db.run("INSERT INTO test VALUES (?,?), (?,?)", [1,111,2,222]);

      // Prepare a statement
      const stmt = db.prepare("SELECT * FROM test WHERE col1 BETWEEN $start AND $end");
      stmt.getAsObject({$start:1, $end:1}); // {col1:1, col2:111}

      // Bind new values
      stmt.bind({$start:1, $end:2});
      while(stmt.step()) { //
        const row = stmt.getAsObject();
        console.log('Here is a row: ' + JSON.stringify(row));
      }
    });
  </script>
  <body>
    Output is in Javascript console
  </body>
</html>

Pictures: https://i.sstatic.net/I5CQU.png

https://i.sstatic.net/6zDfZ.png

I have been attempting to integrate my SQLite file into my test web app for approximately two weeks now. Despite following various suggestions, I still can't seem to successfully execute even the basic example.

Please feel free to share any insights or suggestions you may have.

Thank you!

Answer №1

Encountering the same issue while following the instructions on the sql.js documentation.

To avoid the error, I switched to using sql-asm.js instead of sql-wasm.js. As mentioned in the document later on: "sql-asm.js The older asm.js version of Sql.js. Slower and larger. Provided for compatibility reasons."

This approach works better for me compared to setting up a web server or attempting to "encode the wasm as base64" as suggested in other discussions (which goes beyond my current capabilities while simply trying to create a basic standalone .html page connected to a sqlite file).

Answer №2

Attempting to load the WASM file from a local source is ineffective.

Instead, consider setting up a web server (such as NodeJS) on your machine and executing your test code there. This will allow it to access the file through a valid URL rather than directly from your computer.

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

What steps can I take to resolve this form issue while a script is running?

Currently, I am in the process of constructing a photo archive website for a professional photographer. At the top of each page, there is a convenient search bar that can be easily accessed by clicking on the text that reads "Search the archive..." This en ...

What is the best way to transfer updates to a separate database?

I am looking to synchronize any changes made to specific tables in one database with similar tables in another database. These databases have matching table structures and the tables themselves contain infrequently updated data. However, when there are upd ...

Exploring the Towers of Hanoi Puzzle with Javascript

Recently, I've been working on a school project where I need to present an algorithm for solving the Towers of Hanoi puzzle. Utilizing my knowledge in HTML/CSS, I decided to visually represent the algorithm using JavaScript on a webpage. I've se ...

I need assistance with displaying an ant design flow chart. Can you please provide some guidance?

I am currently working with the ant design chart, specifically the flow chart component. I have been trying to use the basic code found here: "https://charts.ant.design/en/examples/flowchart/basic#basic". Unfortunately, I am encountering an issue where I c ...

There are no HTTP methods being exported in this specific file. Remember to export a named export for each individual HTTP method

Currently, I am working on a React.js/Next.js project that incorporates Google reCAPTCHA. The frontend appears to be functioning properly as I have implemented print statements throughout the code. However, I am encountering an error in the backend display ...

"Creating a Sleek Design: How Bootstrap 4 Tabs Use Fade Effect to Optimize Space for Multiple

In my Rails 5.2 application, I have implemented tabs using Bootstrap 4 as follows: <div class="classic-tabs mx-2 mb-5"> <ul class="nav" id="myClassicTabShadow" role="tablist"> <li class="nav-item"> <a class="nav-link wav ...

find the intersection point of two elements

Is it possible to identify the exact point where two elements overlap? Take a look at the code snippet below that demonstrates what I mean: <html> <head> <style> body { height: 100%; margin: 0; padding: 0; ...

Managing numerous JavaScript objects within a plugin

I have developed a straightforward javascript plugin that enables me to gather data from specific html elements. A page can contain x number of elements (usually up to 20), each with its own settings. However, the issue I am facing is that the returned obj ...

Performing calculations with SQLite to determine the percentage increase within a numeric column

I am seeking advice on calculating the percentage increase or decrease of values in one column compared to the previous value. Could someone please provide guidance on how I can achieve this? Thank you. This is the structure of my table: week | sales ...

Protractor Problem with Asynchronous Calls

New to Protractor, I started by using multiple 'its' in my code. However, I later consolidated everything into one 'it', resulting in the following structure: var UI = require('./../ui.js'); var co = require('co'); ...

Exporting modules for import such as Grid and Grid.Item

Is there a way to utilize two components in the following format: <Container> <Container.Item>X</Container.Item> <Container.Item>Y</Container.Item> </Container> Can you provide instructions on how to export these c ...

Subcomponent in React is not rendering as expected

I have a primary React component with a subcomponent named AttributeInput. To prevent redundancy in my code, I moved some of the logic from the main component to a method within AttributeInput. My attempt at referencing this code looks like this: {this.s ...

Exploring the functionality of the readline module using a simulated command-line

I am currently working on developing a unit test for a module that utilizes the "readline" functionality to interpret standard input and provide standard output. Module: #!/usr/bin/env node const args = process.argv.slice(2) var readline = require(' ...

Is there a way to prevent pushing the same object into an array when adding objects to it?

While working on my project, I encountered an issue when creating a new array with objects checked in the checkboxes. Upon submitting, I received an error message: "flattenChildren(...): Encountered two children with the same key, .$3. Child keys must be u ...

Incorporating the elements of an array into an unordered list for a formatted list display

I have a list here <ul> <li> This is</li> <li> a very nice</li> <li> list</li> </ul> This is a very nice list and this code to insert the array elements into the list var names =["tom", " ...

Is it possible to create a tidy Angular directive that includes an input within an ng-switch?

Summarized I'm seeking a cleaner approach to resolving a problem related to isolate scopes. I am not fully satisfied with my current workaround and hope there is a more effective solution available. View the Demonstration Check out the Demo on Plu ...

Can the loading gif be displayed when a website is loading or when content is being posted

I've implemented two functions in my site master to display and hide a loading GIF. However, I don't want to call it for every AJAX call or before every post method. Is there a way without using jQuery for me to check if the site is loading and ...

Obtain individual information from XML

After fetching data from the server using ajax, I am looking to retrieve only a specific part of the data which is the name. How can I modify my code to achieve this? const url = 'https://jsonplaceholder.typicode.com/users' const xhr = new XMLH ...

Emphasizing hyperlinks according to the user's scrolling location

Currently, I am attempting to create a feature where links are highlighted when the user scrolls over the corresponding section on the page. However, there seems to be an issue with the functionality as Link 2 is highlighting instead of Link 1 as intende ...

I can't understand why my server is displaying an error on the browser stating "This site can't be reached ERR_UNSAFE_PORT" while it is functioning flawlessly on the terminal

I have created an index.html file, along with index.js and server.js. In the server.js file, I have included the following code: const express = require("express"); const path = require("path" ); const app = express(); app.use(" ...