question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Changing requirejs baseUrl has side-effects

See original GitHub issue

I’m submitting a bug report (but I’m not entirely sure if this is a bug or intended)

  • Library Version: 0.21.0

Please tell us about your environment:

  • Operating System: Windows 8

  • Node Version: 6.2.2

  • NPM Version: 3.10.5

  • Browser: all

  • Language: all

Current behavior:

According to the documentation we can set requirejs config settings. I’ve tried to set this:

"baseUrl": "scripts/"

The reason for this is I’d like to dynamically load some components (aka “plugins”) which are not bundled. I’d like to have these components in scripts/plugins/. If I don’t change the baseUrl, the bundle tries to load these plugins from src/plugins, which will not be available on a production server.

If I do change the baseUrl, the module ids are generated to be relative to scripts, so for instance main.js is bundled like this:

define('../src/main', ...

This leads to the bootstrapper not finding any aurelia libs or the main entry point of the app. Other files are bundled with the same prefix (../src/).

Without this change, requirejs modules are defined like this:

define('main', ...

Expected/desired behavior:

  • What is the expected behavior?

In my opinion, setting requirejs baseUrl should only affect the requirejs configuration in vendor-bundle.js.

In other words: If I change this manually in vendor-bundle.js it works as I expect it. Files are bundled correctly and plugins are loaded from scripts/plugins.

I will upload a reproduction repo in a few minutes.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
3cpcommented, May 31, 2022

BTW, I recall when I uses cli-bundler yrs before, I did use gulp-replace to touch the vendor-bundle.js, just replace "baseUrl": "src" to "baseUrl": REQUIREJS_BASE_URL.

I then have the global var set in html file like this <script>var REQUIREJS_BASE_URL="/scripts";</script> which is easy for me to control.

BTW, dumber supported that global var by default. Here is the generated skeleton from dumber:

requirejs.config({
  "baseUrl": (typeof REQUIREJS_BASE_URL === "string") ? REQUIREJS_BASE_URL : "/dist",
0reactions
Alexander-Tarancommented, May 31, 2022

@3cp awesome!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Require.js ignoring baseUrl - javascript - Stack Overflow
When I try to load a module the baseUrl is ignored and require is attempting to load from the same location as main.js...
Read more >
RequireJS API
The baseUrl can be a URL on a different domain as the page that will load require.js. RequireJS script loading works across domains....
Read more >
Module | webpack - JS.ORG
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >
Options - nuxtjs/axios
Defines the base URL which is used and prepended to make server side requests. Environment variable API_URL can be used to override baseURL...
Read more >
How/Where does Magento Convert a RequireJS module ...
So, it's basically one more part of RequireJS config generated by Magento. This baseUrl is calculated on server side and is based on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found