3

Edit 2: The problem is not with webpack but with typescript. Something with declaring "*.md" as a module in a separate declaration file called *.d.ts


Edit: Confirmed the issue is not with webpack itself, since I got the following to work:

import txt from '../documents/test.md'

export default {
  txt,
}

Trying to load text files for rendering client side.

I'm following instructions for raw-loader: https://webpack.js.org/loaders/raw-loader/

I'm also using TypeScript.

import * as React from 'react'
import txt from './file.txt'

export default class HomePage extends React.Component<undefined, undefined> {
  render () {
    return <div>{txt}</div>
  }
}

My webpack config:

module.exports = {
  entry: './src/index',
  output: {
    filename: 'bundle.js',
    path: __dirname + '/dist',
  },

  devtool: 'source-map',

  devServer: {
    hot: true,
  },

  resolve: {
    extensions: [
      '.js',
      '.ts',
      '.tsx',
      '.web.js',
      '.webpack.js',
    ],
  },

  module: {
    rules: [
      { test: /\.tsx$/, loader: 'awesome-typescript-loader', },
      { test: /\.js?$/, loader: 'source-map-loader', enforce: 'pre', },
      { test: /\.txt$/, use: 'raw-loader' },
    ],
  },
}

But all I get is:

ERROR in [at-loader] ./src/pages/Home.tsx:7:21
TS2307: Cannot find module './file.txt'.

What am I missing? Thanks!

6
  • your relative path is correct for sure? Commented Mar 14, 2017 at 17:56
  • Pretty sure, same directory and everything... I'm starting to think the issue is with at-loader or at least typescript related. Commented Mar 14, 2017 at 18:08
  • Can you run webpack with --display-error-details to display more information about the errors? Commented Mar 15, 2017 at 5:56
  • The problem is not with webpack but with typescript. Something with declaring "*.md" as a module in a separate declaration file called *.d.ts. Commented Mar 16, 2017 at 14:18
  • @koder did you find a good resource outlining how to create the typings for '*.md' files? I have exactly the same issue, but with images. Commented Jun 5, 2017 at 12:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.