requirejs ignore my requirejs.config - javascript

here is my files struct:
ex/js/prpr.js
ex/test-requirejs.html
test-requirejs.html
<script>
requirejs.config({baseUrl: "js"})
require(["prpr.js"], function () {
var uri = new Uri("http://baidu.com")
})
</script>
when i google-chrome /home/roroco/Dropbox/jss/ro-js/ex/test-requirejs.html I get error
file:///home/roroco/Dropbox/jss/ro-js/ex/prpr.js Failed to load resource: net::ERR_FILE_NOT_FOUND
Uncaught Error: Script error for "prpr.js"
http://requirejs.org/docs/errors.html#scripterror
at makeError (require.js:168)
at HTMLScriptElement.onScriptError (require.js:1735)
my requirejs version is 2.3.2
how to make requirejs.config work?
update
even I use
require.js
requirejs.config({baseUrl: "js/"})
require(["prpr.js"])
and tag:
<script src="./require.js" data-main="./main.js"/>
I get same error

However I don't know your file structure But from your question I am assuming that it is like this
Project Folder
test-requirejs.html
main.js
require.js
js
prpr.js
If this is your folder structure
then in test-requirejs.html, script tag should be
<script data-main="main" src="require.js"></script>
Your main.js
require.config({
"baseUrl": "js"
})
require(["prpr"],function(){
});
I have tested this by my own and its working

Related

load js file in requirejs-config.js in magento2

how to load this js file in requirejs?
<script type="module" src="https://unpkg.com/#google/model-viewer/dist/model-viewer.min.js"></script>
my requirejs-config.js file=?
var config = {
paths: {
modelviewer: "Ajith_CustomModule/js/modelviewer.min",
.....
.....
.....
and load this file in my phtml file
<script type="module">
require(['jquery'.......,'modelviewer'],function($,..,model){
});
</script>
.....
.....
.....
shows this error =>
Uncaught SyntaxError: Unexpected token 'export'
anybody please help me to fix this problem.
Thanks in advance
RequireJS does not support native JS modules. You have to load it as regular JS module, working example:
<script type="module">
import { ModelViewerElement } from 'https://unpkg.com/#google/model-viewer/dist/model-viewer.min.js';
console.log(ModelViewerElement);
</script>
(tested on Chrome 96)

requireJS, origin of the define statement

I'm working on a large project that uses Requirejs for dependency management, specifically the convention is for every file to have this pattern:
define(['dependency1', 'dependency2'], function (dependency1, dependency2) {
... some code ...
});
now I'm investigating a failure where some file is trying to require a dependency that no longer exists.
I'm getting this error from RequireJS:
GET https://some-location/some-file.js net::ERR_ABORTED
Uncaught Error: Script error for: some-file
http://requirejs.org/docs/errors.html#scripterror
at C (require.min.js:8)
at HTMLScriptElement.onScriptError (require.min.js:29)
at HTMLScriptElement.nrWrapper (...)
How can I know which file contains the faulty dependency?
Simply searching the project files is not good enough since it is a large project that spans across multiple code bases.
Is there a way to make RequireJS tell me who asked for it?
What version of requirejs are you using? I'm using 2.3.2 and the error output provide more info, take a look:
GET http://localhost:9090/requirejs/js/dependency1.js net::ERR_ABORTED
require.js:168 Uncaught Error: Script error for "home/dependency1",needed by: home/somefile
http://requirejs.org/docs/errors.html#scripterror
at makeError (require.js:168)
at HTMLScriptElement.onScriptError (require.js:1735)
Please, note that the part that says needed by: home/somefile is telling us the file that is requiring the failed dependency. This is the small local test I did.
requirejs config
require.config(
{
paths: {
'home': './js'
},
callback: function() {
require(['home/somefile'], function(a) {
console.log(a);
});
}
}
);
./js/somefile.js
define(['home/dependency1'], function (dependency1) {
console.log(dependency1);
});
So, after getting the error Uncaught Error: Script error for "home/dependency1",needed by: home/somefile, we can say that the file requiring the failed dependency is PATH_TO_OUR_PROJECT/js/somefile.js. Remember that we need to pay attention to our paths in the require config.
You can play and test the Global requirejs.onError function but it won't give you more info than the regular requirejs output.
More info in Handling Errors from docs.
Hope it helps.
Following Castro Roy's answer i made a test to verify this is indeed issue of requireJS version.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Require Test</title>
<script data-main="main" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.2/require.min.js"></script>
</head>
<body></body>
</html>
main.js
requirejs(['someFile'], function(someFile) {
console.log('main executing')
});
someFile.js
define(['someDependency'], function (someDependency) {
console.log('someFile executing')
});
and someDependency.js obviously missing.
Results:
using requireJs 2.1.20 (used in my project)
GET http://localhost:63342/playground-simple/someDependency.js net::ERR_ABORTED
Uncaught Error: Script error for: someDependency
http://requirejs.org/docs/errors.html#scripterror
at makeError (require.min.js:1)
at HTMLScriptElement.onScriptError (require.min.js:1)
Then again using requireJs 2.3.2
GET http://localhost:63342/playground-simple/someDependency.js net::ERR_ABORTED
Uncaught Error: Script error for "someDependency", needed by: someFile
http://requirejs.org/docs/errors.html#scripterror
at makeError (require.js:168)
at HTMLScriptElement.onScriptError (require.js:1735)
So clearly Yes.
This is an issue of version and not some unique behavior of my project and this information is given in the error message for later versions of require.
sadly i was not able to find any documentation for this change

Require.js: Load dependency found outside of baseUrl

I have a require.config.js file that looks like this:
require.config({
baseUrl: '/some/path',
paths: {
module1: '../../path/to/my/module'
}
});
Why does the following work:
define(function(require) {
const module1 = require('module1');
});
But this doesn't?
require(['module1'], ...);
When I run the above, it tries to load the dependency from the baseUrl and errors out:
require.js:168 Uncaught Error: Script error for "module1"
http://requirejs.org/docs/errors.html#scripterror
at makeError (require.js:168)
at HTMLScriptElement.onScriptError (require.js:1735)
Not even sure if this is the right question to ask. Any help is appreciated
Give your require.config I believe you would need this
require(['module1/module1'], ...);
So basically you need to include the defined path to the required file.

Uncaught SyntaxError: Unexpected token < VM105:17Uncaught ReferenceError: System is not defined

I am serving my index.html from nodejs server. This ng2 file works fine with the live-server. but when I load it from nodejs index.js with specific routes it gives the following error.
Uncaught SyntaxError: Unexpected token <
VM105:17Uncaught ReferenceError: System is not defined
I have loaded the files right. Here are the loaded files:
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.33.3/es6-shim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.16/system-polyfills.js"></script>
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.min.js"></script>
<script src="node_modules/angular2/bundles/angular2.min.js"></script>
<script src="node_modules/angular2/bundles/router.js"></script>
<script src="node_modules/angular2/bundles/http.js"></script>
<!-- 2. Configure SystemJS and Import -->
<script>
System.config({
packages: {
client: {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('client/boot')
.then(null, console.error.bind(console));
</script>
What am I missing? All the files are served from the node server.
Most of time when you have the error Uncaught SyntaxError: Unexpected token <, this means that there a 404 error on the file referenced within a script element.
I think that you Node serve doesn't make available your node_modules folder. So the node_modules/systemjs/dist/system.src.js file can't be loaded (it's also true for other files in node_modules).

When Loading html file with require.js error with extension

I have file
reg.html
<label>Name:</label>
in require.config :
requirejs.config({
paths: {
reg:"/templates/reg.html"
}
})
When i try load template :
define('ng_start',["angular","jquery","reg"],function(An,$,template){
....
})
GET /templates/registry.html.js?bust=1417489939824228.12310815788805
require.js:166 Uncaught Error: Script error for: registry
http://requirejs.org/docs/errors.html#scripterror
How deleted js extension from registry.html.js ?
You need to state that your "reg" module is to be loaded as text and not as a JavaScript module. See the following for details:
https://github.com/requirejs/text
Your specific code should read:
define('ng_start',["angular","jquery","text!reg"],function(An,$,template){
....
})
note: the addition of text! in the module definition requirements for reg.

Categories

Resources