GithubHelp home page GithubHelp logo

Comments (8)

bogdan avatar bogdan commented on June 25, 2024

What is your JsRoutes configuration?

from js-routes.

khiemb avatar khiemb commented on June 25, 2024

i followed the 2.0 upgrade doc, so this is

config/initializers/js_routes.rb

JsRoutes.setup do |config|
  config.module_type = nil
  config.namespace = "Routes"
end

from js-routes.

bogdan avatar bogdan commented on June 25, 2024

I can't reproduce it locally because JS environments are too diverse.

For the sake of debugging can you change the following method locally inside your copy of js-routes gem to:

            isSupported() {
               console.log(Root);
               console.log(Namespace);
               console.log(!!Root);
               return true;
            },

return !RubyVariables.NAMESPACE || !!Root;

And then restart the project and tell me if it fixes your issue and what is the output in console?

from js-routes.

khiemb avatar khiemb commented on June 25, 2024

I made the changes and this is the console output



routes.js.erb:77 undefined
routes.js.erb:78 Uncaught ReferenceError: Namespace is not defined
    at Object.isSupported (routes.js.erb:78:1)
    at UtilsClass.is_module_supported (routes.js.erb:476:1)
    at UtilsClass.ensure_module_supported (routes.js.erb:479:1)
    at UtilsClass.define_module (routes.js.erb:484:1)
    at routes.js.erb:1402:1
    at Module.<anonymous> (routes.js.erb:1404:1)
    at Module../app/javascript/routes.js.erb (routes.js.erb:1406:1)
    at __webpack_require__ (bootstrap:84:1)
    at Module../app/javascript/packs/application.js (application.js:1:1)
    at __webpack_require__ (bootstrap:84:1)

from js-routes.

bogdan avatar bogdan commented on June 25, 2024

I tried to fix an issue. Can you try the gem from current master if it solves the problem?

from js-routes.

khiemb avatar khiemb commented on June 25, 2024

I tried the gem from current master, and getting this error in routes.js.erb at

export default this.Routes

Uncaught TypeError: Cannot read properties of undefined (reading 'Routes')
    at Module.<anonymous> (0-c0a5c58e421ed5570b29.chunk.js:2025:74)
    at Module../app/javascript/routes.js.erb (0-c0a5c58e421ed5570b29.chunk.js:2026:30)
    at __webpack_require__ (runtime~application-aa001ceb574a6f67800d.js:80:30)
    at Module../app/javascript/packs/application.js (application-96c4f6da898f33e3ba24.chunk.js:170:72)
    at __webpack_require__ (runtime~application-aa001ceb574a6f67800d.js:80:30)
    at Object.1 (application-96c4f6da898f33e3ba24.chunk.js:2815:18)
    at __webpack_require__ (runtime~application-aa001ceb574a6f67800d.js:80:30)
    at checkDeferredModules (runtime~application-aa001ceb574a6f67800d.js:46:23)
    at Array.webpackJsonpCallback (runtime~application-aa001ceb574a6f67800d.js:33:19)
    at application-96c4f6da898f33e3ba24.chunk.js:1:57
    

from js-routes.

bogdan avatar bogdan commented on June 25, 2024

See, there is a kind of problem within webpacker environment: top level this is equal to undefined.
The problem is that you need to use one os the following depending on the JS environment: window, this or global.
You need to use this code snippet if you really need that: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis#search_for_the_global_across_environments

Overall I do not recommend a configuration like this. It is not environment agnostic.

You should try instead:

JsRoutes.setup do |config|
  config.module_type = nil
end
const Routes = <%= JsRoutes.generate %>
export Routes;

from js-routes.

bogdan avatar bogdan commented on June 25, 2024

No followup, closing. Feel free to reopen.

from js-routes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.