Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 网页包和类型脚本:未找到模块:错误:无法解析';文件';或';目录';_Typescript_Webpack - Fatal编程技术网

Typescript 网页包和类型脚本:未找到模块:错误:无法解析';文件';或';目录';

Typescript 网页包和类型脚本:未找到模块:错误:无法解析';文件';或';目录';,typescript,webpack,Typescript,Webpack,我正在尝试使用Webpack编译TypeScript,但由于某些原因,它在导入时失败: ./path/to/MySource.ts中出错 找不到模块:错误:无法解析“文件”或“目录”。/path/to/MyIncludedFile in 尽管MyIncludedFile.ts实际上在那里,IDE也可以识别导入,但TypeScript编译器找不到该文件。运行带有的Webpack--显示错误详细信息我得到了一些额外信息: /path/to/MyIncludedFile doesn't exist /

我正在尝试使用Webpack编译TypeScript,但由于某些原因,它在导入时失败:

./path/to/MySource.ts中出错 找不到模块:错误:无法解析“文件”或“目录”。/path/to/MyIncludedFile in


尽管
MyIncludedFile.ts
实际上在那里,IDE也可以识别导入,但TypeScript编译器找不到该文件。

运行带有
的Webpack--显示错误详细信息
我得到了一些额外信息:

/path/to/MyIncludedFile doesn't exist
/path/to/MyIncludedFile.webpack.js doesn't exist
/path/to/MyIncludedFile.web.js doesn't exist
/path/to/MyIncludedFile.js doesn't exist
/path/to/MyIncludedFile.json doesn't exist
因此,我意识到Webpack没有寻找正确的扩展名,在我的例子中是
.ts

为了解决这个问题,我修改了我的
webpack.config.js
添加了以下内容:

resolve: {
    extensions: ['.ts']
}
在我的模块配置中。更具体地说,我的模块网页包配置现在如下所示:

module.exports = [
  {
      entry: /* my entry config */
      output: {
          /* my output config */
      },
      module: {
          loaders: [
              {
                  test: /\.ts/,
                  loaders: ['ts-loader']
              }
          ]
      },
      /* ... other stuff ... */
      resolve: {
          extensions: ['.ts']
      }
  },
  /* ... other modules ... */
]

运行带有
--显示错误详细信息的Webpack
我获得了一些额外信息:

/path/to/MyIncludedFile doesn't exist
/path/to/MyIncludedFile.webpack.js doesn't exist
/path/to/MyIncludedFile.web.js doesn't exist
/path/to/MyIncludedFile.js doesn't exist
/path/to/MyIncludedFile.json doesn't exist
因此,我意识到Webpack没有寻找正确的扩展名,在我的例子中是
.ts

为了解决这个问题,我修改了我的
webpack.config.js
添加了以下内容:

resolve: {
    extensions: ['.ts']
}
在我的模块配置中。更具体地说,我的模块网页包配置现在如下所示:

module.exports = [
  {
      entry: /* my entry config */
      output: {
          /* my output config */
      },
      module: {
          loaders: [
              {
                  test: /\.ts/,
                  loaders: ['ts-loader']
              }
          ]
      },
      /* ... other stuff ... */
      resolve: {
          extensions: ['.ts']
      }
  },
  /* ... other modules ... */
]

我也遇到了这个错误,并用
--显示错误详细信息
(在较新的网页版本中,参数的尾部有一个
s
!)进行了尝试

结果我忘了扩展数组中的点。添加它们解决了这个问题

resolve: {
  extensions: ['.ts', '.tsx', '.js']
//              ^      ^       ^
//              |      |       |
//           don't forget these dots!
}

我想,有时候是微小的细节和巨大的错误日志导致了解决方案。希望它能对将来的人有所帮助。

我也遇到了这个错误,还尝试了
--显示错误详细信息
(在较新的网页版本中,参数后面有一个
s
!)

结果我忘了扩展数组中的点。添加它们解决了这个问题

resolve: {
  extensions: ['.ts', '.tsx', '.js']
//              ^      ^       ^
//              |      |       |
//           don't forget these dots!
}
我想,有时候是微小的细节和巨大的错误日志导致了解决方案。希望它能帮助将来的人