Webpack loader cannot find module

限于喜欢 提交于 2019-12-11 04:25:28

问题


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!

来源:https://stackoverflow.com/questions/42793207/webpack-loader-cannot-find-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!