Application.js can't find #rails - javascript

I'm updating a fairly old project to rails 6, and adapt to current "rails ways". And I've just installed webpacker, but I've run into problem I can't seem to find a way to solve.
When running the project, I get this error: Uncaught Error: Cannot find module '#rails/ujs'
I've tried to reinstall rails-ujs through yarn, but to no effect.
Also I've tried to comment the line require("#rails/ujs").start() from my app/javascript/packs/application.js, and yet I got another error: Uncaught Error: Cannot find module '#rails/activestorage'.
Which leads me to believe that its the global #rails that is not being recognized, however I have no idea where is it set or how to do so.
My questions are:
Can I set #rails myself?
Is there a way to re-generate it?
or
Is there another configuration I should fix?

It’s not #rails which is missing, it’s the ujs (and active storage) JavaScript packages which are missing.
Run yarn install To install them.

Related

React: Unable to start old projects. Why?

I am unable to npm start my old React projects (created in October and before, ex: https://github.com/DebojyotiRoy15/Calculator-app). When I try to do it, I get the following error:
I have tried various things suggested in stackoverflow to solve this error, like adding a .env file to the root, deleting package-lock, deleting node modules and then installing them. But still this error persists. Please help me to resolve this.
I managed to run your app without any issues, check it out here https://codesandbox.io/s/wizardly-dream-s5w2e. Your error is probably due to some package resolving behavior of Node.JS. Try renaming the C:\Users\Pavilion\node_modules\babel-jest", and if it didn't help then run npm i babel-jest --save-dev and reload your app again.

Assertion Error : App Version has already been registered

Im using ember to develop a project.
Please help me with this error. Im unable to run my project on local. After hitting
ember server the build is successful. But on hitting the http://localhost:4200
Loads empty page with console error.
Uncaught Error: Assertion Failed: The initializer 'App Version' has already been registered
at assert (index.js:172)
at Function.initializer (index.js:420)
at registerInitializers (index.js:27)
at loadInitializers (index.js:68)
at Module.callback (app.js:25)
at Module.exports (loader.js:106)
at requireModule (loader.js:27)
at app-boot.js:3
Unable to understand what to do. Any help regarding this would be appreciated.
I did a code search to see where that initializer might exist and it looks to be part of ember-cli-app-version.
In your place I would remove ember-cli-app-version from your app with npm uninstall --save-dev ember-cli-app-version and then run ember serve again. The purpose of this addon is to make it easy to see your app's version number in the ember inspector, but that's not a big deal so removing it won't break anything and should get you moving forward.
If you want to investigate the issue further try searching your code base (including node_modules) for App Version to see where a duplicate exists.
Running npm install solved the problem.
The actual issue was due to the iCloud sync being active in my Macbook.
Turning iCloud sync off should solve the problem.

Why does npm try to compile a old version of my code?

I'm totally new to npm and node.js so please forgive me if I'm not giving the right detail. I'm writing a plugin for a website that uses an out-of-the-box framework in npm. It was working fine as I coded away happily, but at some point it started trying to compile a file that no longer exists.
I use npm run start to compile my html file (which contains all the javascript code as well) and get this error:
ℹ info Compiler will compile ./src/plugin.html
ℹ info Transpiling with babel
✖ error Error
SyntaxError: unknown: Unexpected token (555:3)
553 |
554 |
> 555 | });
| ^
What breaks my brain is that this simple syntax error is not present in ./src/plugin.html (I've quadruple checked this fact). This obvously pertains to an earlier version of the file.
Does npm have some kind of cache that would cause it to compile an older version of a file? I've noticed that if I remove most of the code, it compiles again, but when I replace the code it breaks again. It seems that if the file is somewhat similar to its cached version, it tries to compile the cached version and not the current version.
I've tried clearing the cache with npm --force cache clear but to no effect.
Any suggestions?
For anyone who has a similar problem with compiling code with npm, I discovered that my problem was indeed a simple syntax error. But it seems that npm became confused about what the compile error actually was. It was pointing to a line of code that did not exist in the file, and I have no idea where it got this from.
The syntax error that was the culprit in this particular case was a missing }; to close a wrapped set of functions.
So it seems that the lesson here is not to put too much trust in npm's ability to understand what syntax errors are inciting a compile error.
the only way I was able to get out of this scenario was:
rename the file
refactor the references to it, so it will compile
npm start
stop it
rename and refactor the file back to its original name
Do you try to use rebuild or something like that or npm cache clean insted of npm --force cache clear?
I had the same problem after a cancelled git rebase. The only way I could fix this was to change something in those files & revert the change after.
I recently faced this issue. If you are using typescript in your project, you may have used a wrong configuration in your tsconfig.json file that may have built the typescript files into their corresponding js files and these js files are the ones that runs every time you run the project.
for me clear catching my browser it works
Fixed by Pressing Ctrl+s !
For me vsc by default doesn't save automatically changed code like PyCharm.
Try to delete .next folder it will delete the catched files

uncaught DOMException after installing and using polymer element

I am following this tutorial which teaches the installation of polymer elements:
https://www.polymer-project.org/3.0/start/toolbox/add-elements
After running the npm install command and importing it using:
import '#polymer/paper-checkbox/paper-checkbox.js';
I am starting to get this error when the page loads:
Uncaught (in promise) DOMException: Failed to execute 'define' on 'CustomElementRegistry': this name has already been used with this registry
I had a look around and some say delete node models folder and others say to reinstall web components because there are conflicts between versions but none go into great detail on how this is done.
For me, deleting node_modules and package-lock.json, then running npm install fixed this. It appears to be due to duplicate dependencies within paper elements.

Problems with Rails and JavaScript runtime on Windows machine

I am currently in a web development class and we are using Ruby on Rails.
I am using Ruby v1.9.2 and Rails v3.1.1.
My initial problem started when I tried to execute 'rails server'.
I would get the following error:
C:\Sites\rorProjects\basicRoRProject>rails server
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/execjs-1.2.13/lib/execjs/runtimes.rb:47:in `autodetect': Could not find a JavaScript runtime.
See https://github.com/sstephenson/execjs for a list of available runtimes.(ExecJS::RuntimeUnavailable)
I have done some reading and the general consensus is to install the gems 'execjs' and 'therubyracer'. 'execjs' installed just fine, however when I tried to install 'therubyracer' I got the following error:
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing therubyracer: ERROR: Failed to build gem native extension.
C:/RailsInstaller/Ruby1.9.2/bin/ruby.exe extconf.rb
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers.
Check the mkmf.log file for more details.
You may need configuration options.
I then did some more reading and found a couple of people said to check that they had the gem 'libv8', which was required for 'therubyracer'. I did that and discovered that I didn't have it, so I then went to install that and got the same error that I did for 'therubyracer'.
I'm at a loss to think of anything else to do. Any help would be greatly appreciated.
Thanks guys!
THIS PROBLEM HAS BEEN SOLVED.
So, with the help of one of my classmates who had a similar problem, I installed Node.js using the Windows installer (this gave me a JavaScript run-time environment). I then added it to the path in the local variables.
So, with the help of one of my classmates who had a similar problem, I installed Node.js using the Windows installer. I then added it to the path in the local variables.

Categories