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.

Problem with 'text' require.js plugin

See original GitHub issue

Hello!

I have a big problem when try migrate from require.js to webpack. my config:

var path = require("path");
var webpack = require("webpack");
var appModulesPath = path.join(path.resolve('public/app/js'));
var libsPath = path.join(path.resolve('public/app/lib'));
module.exports = {
  cache: true,
  context: appModulesPath,
  entry: {
      entryMain: './main',
      // entryLogin: 'main-login'
  },
  output: {
    path: path.join(__dirname, "dist"),
    publicPath: "dist",
    filename: "[name].js",
    chunkFilename: "[chunkhash].js"
  },
  module: {
    loaders: [
      { test: /require\.js$/, loader: "exports?requirejs!script" },
      { test: /text!\.html$/, loader: "html" }
    ]
  },
  externals: {
    // require("jquery") is external and available
    //  on the global var jQuery
  },
  resolve: {
    root: [appModulesPath, libsPath],
    alias: {
        "text": 'text.js',
        "angular": 'angular/angular.js',
        "angularRoute": 'angular-route/angular-route.js',
        "angularCookies": 'angular-cookies/angular-cookies.js',
        "angularMocks": 'angular-mocks/angular-mocks.js',
        "jquery": 'jquery.js',
        "wysihtml5": 'wysihtml5.js',
        "gritter": 'jquery.gritter.js',
        "icheck": 'jquery.icheck.js',
        "placeholder": 'jquery.placeholder.js',
        "qtip": 'jquery.qtip.js',
        "tooltipster": 'jquery.tooltipster.min.js',
        "almond": 'almond/almond.js',
        "cryptojs": 'cryptojs/hmac-sha1.js',
        "datepicker": 'bootstrap-datepicker.js',
        "slider": 'jquery-ui-slider.js',
        "select2": 'select2.js',
        "toastr": 'toastr.js',
        "requirejs": 'requirejs/require.js'
    }
  },
  plugins: [
    new webpack.ProvidePlugin({
      // Automtically detect jQuery and $ as free var in modules
      // and inject the jquery library
      // This is required by many jquery plugins
      jQuery: "jquery",
      $: "jquery"
    })
  ]
};

Then, i use for require html => require.js text plugin.

when i run webpack:

ERROR in ./servers/partition-modal.js
Module not found: Error: Cannot resolve module 'text' in /private/var/www/webzilla/ssp/public/app/js/servers
 @ ./servers/partition-modal.js 3:0-173:2

example file:

'use strict';

define([
    'app',
    'text!servers/tpl/cart.html'
], function(
    app,
    tpl
) {
    app.controller('CartCtrl', [
        '$scope',
        '$location',
    function(
        $scope,
        $location
    ){
    }]);
});

What i do wrong?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

11reactions
michaelahlerscommented, Aug 25, 2015

@SimenB, one possible reason for preserving the text and other Require.js plugins (and syntax): ease legacy transitions to webpack. I’m currently migrating a large project, and I’m trying to be minimally invasive wherever possible.

9reactions
johnstewcommented, Jan 14, 2017

I know its been awhile on this thread but came across this problem when I was trying to integrate Webpack 2 as our new bundler. Anyways here is my solution following @sokra advice.

webpack.config.js

resolveLoader: {
  alias: {
      text: 'text-loader'
  }
}

Also going to need text-loader.

Read more comments on GitHub >

github_iconTop Results From Across the Web

requirejs/text: An AMD loader plugin for loading text resources
A RequireJS/AMD loader plugin for loading text resources. Known to work in RequireJS, but should work in other AMD loaders that support the...
Read more >
Plugins - RequireJS
RequireJS allows you to write loader plugins that can load different types of resources as dependencies, and even include the dependencies in optimized...
Read more >
RequireJS text plugin: cannot load HTML from other domain
I've found the actual problem! This part: config: { text: { useXhr: function (url, protocol, hostname, port) { return true; } } },....
Read more >
requirejs-text - npm
An AMD loader plugin for loading text resources. ... Start using requirejs-text in your project by running `npm i requirejs-text`.
Read more >
Javascript – require.js text plugin adds “.js” to the file name
The documentation of the text plugin gives a hint to the solution: It's possible to configure the plugin in a way that it...
Read more >

github_iconTop Related Medium Post

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