Amber CLI (amberframework.org) - v0.11.3 Crystal 0.27.0 [c9d1eef8f] (2018-11-01) LLVM: 4.0.0 Default target: x86_64-unknown-linux-gnu npm 3.5.2
Attempting to incorporate sockets using Crystal Lang and Amber has hit a snag. Despite following the guidelines outlined in the Amber Docs as well as the instructions on Github Amber Readme, an error is persisting.
The process involves running "npm run watch" and "amber watch," which successfully triggers a browser refresh whenever changes are made to main.js.
//main.js
import 'bootstrap';
import $ from 'jquery';
import Amber from 'amber';
let socket = new Amber.Socket('/notification')
socket.connect().then(function() {
let channel = socket.channel('chat_room:hello');
channel.join();
channel.push('message_new', {
message: "Hello Amber from WebSocket Client!"
});
channel.on('message_new', function(payload) {
console.log(payload);
});
});
// Uncaught TypeError: Cannot read property 'Socket' of undefined
// at Module../src/assets/javascripts/main.js (main.js:28)
// at __webpack_require__ (bootstrap:19)
// at Module../config/webpack/entry.js (entry.js:1)
// at __webpack_require__ (bootstrap:19)
// at bootstrap:83
// at bootstrap:83
UPDATE:
Closer inspection revealed the existence of two versions of main.js. The version triggering the error resides in "webpack://.src/assets/javascripts/main.js." Examination during run-time showed that Amber could not be found, leading to a "ReferenceError: amber is not defined." On the other hand, the second version of the file is situated in "/dist/main.bundle.js." Puzzlingly, both assets are being served simultaneously. Could this issue potentially stem from npm?