Guide on utilizing node-modules installed via npm in a template

I am attempting to utilize a library installed via npm in the Go template.

By running 'npm install three', I have successfully installed the required three libraries, which are saved in the root folder as depicted in the provided screenshot below.

https://i.stack.imgur.com/u1cx9.png

However, even after trying to import and use the three.js module as demonstrated below, I encountered an issue wherein 'threejs' is not detected.

I suspect that there may be an issue with the filesystem. How can I seamlessly incorporate threejs in my current scenario without any hitches?

import * as THREE from "/three";

class App{
    constructor(){
        // Scene
        const scene = new THREE.Scene();

        // Camera
        const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);

        // Renderer
        const renderer = new THREE.WebGLRenderer();
        renderer.setSize(window.innerWidth, window.innerHeight);

        document.body.appendChild(renderer.domElement);

        renderer.render(scene, camera);
    }
}

window.onload = function(){
    new App();
}

Error encountered:

import * as THREE from "/three";

http://localhost:8081/three net::ERR_ABORTED 404 (Not Found)

Attempted solution:

import * as THREE from "three";

Uncaught TypeError: Failed to resolve module specifier "three". Relative references must start with either "/", "./", or "../".

Solution suggested:

e.Static("/node", "node_modules") in main.go

import * as THREE from "/node/node_modules/three/builld/three.module.js";

GET http://localhost:8081/node/three/builld/three.module.js net::ERR_ABORTED 404 (Not Found)

Answer №1

<script type="importmap">
    {
        "imports": {
            "three": "/node/three/build/three.module.js"
        }
    }
</script>

The issue was resolved by updating the path to the task.

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

Updating NPM packages versions is currently restricted

I'm in the process of creating a Next.JS application using create-next-app. However, I've noticed that in the package.json file it lists the following dependencies: "eslint": "8.43.0", "eslint-config-next": &quo ...

In the following command, where is the PORT stored: ~PORT=8080 npm App.js?

section: Let's consider the following code snippet located in the App.js file: console.log(`This is the port ${process.env.PORT}`); Is there a method to retrieve the value of PORT from outside the running process? ...

Node.js encountered an abrupt conclusion in the JSON input that was not anticipated

Upon receiving Json data as post data in my node.js server, I encountered an issue with parsing the string. Here is a snippet of my node.js server code: res.header("Access-Control-Allow-Origin", "*"); req.on('data',function(data) { var ...

Is it possible to have all dependencies exclusively in devDependencies?

Is it possible to classify all dependencies of a React-based website as devDependencies rather than (production) dependencies? Given that the build folder is not included in the code versioning, every instance of checking out the repository will necessita ...

Encountering Issues with Gatsby Build Due to Mozjpeg

Since yesterday, I've been facing issues deploying my Gatsby site to our server due to a problem with the mozjpeg library. Has anyone else run into this error before? I've attempted: locking gatsby-cli installing the automake linux package inst ...

Git only keeps track of the changes made to files, not the

I am facing an issue with my npm project. Whenever I run npm start A bundle of files is created, named like *-bundle.gz If I make minor changes to files like font.php, and then run npm start again, new files named *font-bundle.gz are generated with a n ...

I'm having trouble locating the module "script!foundation-sites/dist/foundation.min.js on Heroic."

This is the content of my webpack.config.js file: var webpack = require('webpack'); var path = require('path'); process.env.NODE_ENV = process.env.NODE_ENV || 'development'; module.exports = { entry: [ 'script!jque ...

Error 403 encountered during npm install on Azure Pipeline when accessing Azure Feed

Currently, my NPM install step is set up to utilize registries in the .npmrc file. https://i.stack.imgur.com/SNjgq.png Here's how my .npmrc file looks: registry=https://pkgs.dev.azure.com/xxx/xxxx-xxxx-xxxx/_packaging/design-system/npm/registry/ al ...

A guide on compiling Sass without using gulp and Laravel Elixir [SOLUTION]

If you encounter an error similar to this one: https://i.stack.imgur.com/ZqVeV.png You have come to the right place :) ...

Error message on npm start command: Issue with finding Parse server module

After successfully setting up npm on my local machine and creating a project using parse, I encountered an issue when trying to run the project with the command npm start. The error originates from a specific line of code in the index.js file. var api = n ...

Using the set() method in Firestore with the merge option does not function properly when implemented in Node.js

const user = {name : myUsername}; databaseRef.set(user, { merge: true }); An error is occurring which states: Invalid use of type "undefined" as a Firestore argument. Despite following the Firebase documentation here, and seeing others use it in online ...

What are the steps to generating and sharing 'npm create' scripts?

I am looking to develop and release a script on npm that functions similarly to: npm create qwik@latest or yarn create next-app --typescript However, I am unsure where to begin. Despite searching extensively online, I have not been able to find any helpf ...

Utilizing React components from npm in Rails: A comprehensive guide

Recently delving into the world of react, I came across an insightful article on integrating React with Rails at . The transition was seamless until I attempted to incorporate Summernote (a WYSIWYG html editor) into my records.html page. Despite discoverin ...

Issues encountered during the installation of dependencies using npm install

I'm feeling lost. I just cloned my repository from github and attempted to install the dependencies using npm install, but I encountered a bunch of errors. It was working perfectly fine yesterday. Node version: 16.16.0 npm version: 8.13.2 Operating ...

Having difficulty executing the command 'npm install -g expo-cli'

When attempting to execute npm install - g expo-cli on a Windows 10 machine, I am encountering issues. An error message keeps popping up and preventing me from proceeding. I'm in desperate need of assistance! npm WARN deprecated <a href="/cdn-cgi/ ...

Difficulty encountered while setting up node and npm on Manjaro operating system

Operating System: Manjaro I added npm and nodejs using the following command: sudo pacman -S nodejs npm However, I encountered an error after installation: ~]$ npm -v node: error while loading shared libraries: libicui18n.so.67: cannot open shared ob ...

Is it possible to transmit a struct Type in Golang?

As a newcomer to Golang, I seek forgiveness for my lack of knowledge and potential incorrect approach. Currently, I am working on developing a Terraform provider for an internal service. This involves unmarshalling JSON data into pre-defined Struct Types ...

Unable to locate the module

throw err; ^ Error: The module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js' cannot be found at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15 ...

How can the issue of encountering the npm error "gulp-cli module not found" when executing gulp be resolved, even after gulp-cli has been successfully installed?

I've been trying to follow a SASS tutorial on YouTube by net-ninja, which you can watch here. The tutorial recommends installing gulp with SASS. Unfortunately, I've encountered an issue where I can't seem to get gulp to work properly. Follow ...

Installation of Axios on Firebase Functions with Node.js 14 encountered errors

While working with Firebase Functions, I encountered an issue when attempting to install and use axios. Despite using npm install to add the package as shown below, the installation failed without any clear indication of what went wrong during runtime. Co ...