Requirement for Action with RequireJS

I use node, react and requirejs (and create my JM-compatible JS from Typescript, but I don't think this is relevant to the problem). I am just trying to require React in my application:

// config.js
require.config({
    baseUrl: '../scripts/lib/node_modules',
    paths: {
        lib: '..',
        react: 'react/lib', 
        app: '../../app',
        jquery: 'jquery/dist/jquery',
        scripts: '../..',
    },
});
require(['react/React'], function (react) {

});

Then I will load this configuration using the RequireJS data-mainapi by going to this page:

<!DOCTYPE html>
<html>
    <head>
        <title>My Updated Test Project</title>
        <script data-main="../scripts/config.js" src="../scripts/lib/node_modules/requirejs/require.js"></script>
    </head>
    <body>
        <h1>My Test Project</h1>
    </body>
</html>

RequireJS complains when trying to download React:

Error: Module name "EventPluginUtils" has not been loaded yet for context: _. Use require([])

In React.js, almost the first line is "bare required"

var EventPluginUtils = require("./EventPluginUtils");

If I read RequireJS information about this error message, it says that the fix is ​​to stop using bare require.

, require ('name'), 'name' . Use require ([]), ( define()), ,

, AMD , React. ? , React.js require ? . - RequireJS? ( ).

Edit:

React CommonJS, : RequireJS : http://requirejs.org/docs/api.html#packages.

, React package.json, , . baseUrl, , .

+4
2

, React , .

React from RequireJS, . , . NPM React script, React, . , .

, . , , require, , . Webpack ( " " ).

. .

, . , , . , , , . Webpack , Webpack, DLL-, , .

vs webpack? webpack. (, , ), , , , , .

, typescript, , : CommonJS, AMD . , tsconfig.json.compilerOptions.module. "amd", "commonjs", "umd" . webpack "commonjs". ( , webpack typescript , .)

RequireJS, -. , , . , , . - , , . webpack , . .

+3

Browserify (npm install browserify) requirejs.I , - requirejs .

Browserify, . , , : http://youtube.com/watch?v=78_iyqT-qT8

-1

Source: https://habr.com/ru/post/1599780/


All Articles