webpack-contrib/raw-loader

SyntaxError: Unexpected token

malyzeli opened this issue · 1 comments

This is my test component (works well without trying raw-loader):

import test from "raw-loader!./test.txt";

class Application extends React.Component {
    componentWillMount() {
        console.log(test);
    }
}

This is test.txt content:
some text here

This is what I'm getting when trying to build by webpack:

ERROR in ./~/raw-loader!./src/app/test.txt
Module build failed: SyntaxError: Unexpected token, expected ; (1:5)

> 1 | some text here
    |      ^

 @ ./src/app/Application.jsx 13:12-44

Using "raw-loader": "^0.5.1".
Tried with both Webpack v1 (1.14.0) and v2 (2.2.1), result is the same.
What am I doing wrong?!

Okay, so the problem was that other loaders from config was still applied after raw loader.

Solution was to add !! to import statement, which disables other loaders, so its
import test from "!!raw-loader!./test.txt

See https://webpack.github.io/docs/loaders.html#loader-order