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.

text! plugin could not load the HTML template during test

See original GitHub issue

It appear when using Karma with Require.js, it cannot load text! plugin. I am getting

Error: /base/app/assets/javascripts/src/client/templates/show.html HTTP status: 404

But if I change the file extension to show.js, it can be loaded. It appear that it only accept JavaScript file?

Here is the proof-of-concept repo to product this: https://github.com/mech/front_end_demo

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:21 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
luddercommented, Jul 17, 2014

FWIW: I’m using karma 0.12.16 and karma-requirejs 0.2.2 and for me it was just enough to add this line to karma.conf.js to successfully load a template via the text plugin and prevend a 404:

(files: [{pattern: 'templates/*.html', included: false}])

1reaction
ianjiangcommented, Sep 28, 2013

@ievgenneiman:

text! requirejs can’t load html in Karma solution

  • Root cause: can’t include html file. Karma includes files as <script src="...">, so this would lead into “unexpected token” error.
  • That’s why by default Karma comes with html2js preprocessor which puts the HTML content into a global __html__['some.html']. This is why Karma serves test.html.js instead of test.html.
  • Solution step one: disable the preprocessor
preprocessors: {}
  • Solution step two: configure the html files to NOT be incldued
files: [{pattern: 'templates/*.html', included: false}]
  • Then, Karma will serve the templates/x.html, but not include it, so that require.js can fetch it on its own.
  • requirejs configuration: Use TestSuite.js to load needed test cases files. Note: If use deps to load test cases, could meet with unexpected < error. So use a module to load all test cases.
requirejs.config({
    //Karma serves files from '/base'
    baseUrl: 'base',

    // add text! plugin
    paths : { 
        text  : 'lib/text'
    },

    // ask Require.js to load these files (all our tests)
    //deps: tests,

    // start test run, once Require.js is done
    callback: function() {
        console.log('start to load test cases!');
        require(['test/TestSuite'], function() {
            console.log('load all test cases done!');
            window.__karma__.start();
        });
    }
});

  • TestSuite.js
define(['test/active/test'], function() {
    console.log('TestSuite');
});

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
Using the Text Plugin With RequireJS To Load Remote HTML ...
Ben Nadel demonstrates how to use the Text plugin with RequireJS to load remote HTML templates for client-side DOM augmentation.
Read more >
Envato Elements Template Kits - Troubleshooting Common ...
This guide provides general help for common issues you may encounter when using the Template Kit Import or Envato Elements plugins.
Read more >
How to Fix the 'Preview Could Not Be Loaded' Error - Elementor
If you receive the error message “the preview could not be loaded”, try the following: · Enable Safe Mode. · Make sure the...
Read more >
Handling common HTML and CSS problems - MDN Web Docs
This is a common problem, especially when you need to support old browsers (such as Internet Explorer) or you are using features that...
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