Javascript 打字脚本可以';无法导入没有扩展名的文件

Javascript 打字脚本可以';无法导入没有扩展名的文件,javascript,node.js,angular,typescript,webpack,Javascript,Node.js,Angular,Typescript,Webpack,我正在尝试在我的新Angular2项目中导入文件。 条目文件“main.ts”能够使用以下方式导入其他typescript文件: import { AppModule } from './module/app.module'; 另一方面,“app.module.ts”无法导入没有文件扩展名的ts文件: import { AppComponent } from '../component/app.component'; 如果我在文件名中添加“.

我正在尝试在我的新Angular2项目中导入文件。 条目文件“main.ts”能够使用以下方式导入其他typescript文件:

import { AppModule }              from './module/app.module';
另一方面,“app.module.ts”无法导入没有文件扩展名的ts文件:

import { AppComponent }             from '../component/app.component';
如果我在文件名中添加“.ts”,一切都会按预期进行

我犯了什么错?我假设我做的每件事都是按照角度指南()

我已经安装了node 6.9.4、npm 4.2.0、typescript 2.3.2、Angular 4.1.0和Webpack 2.5.1

我的tsconfig.json

{
    "compilerOptions": {
        "target": "es6",
        "module": "commonjs",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "noImplicitAny": true,
        "suppressImplicitAnyIndexErrors": true
    }
}
My webpack.config.js

var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var helpers = require('./helpers');

module.exports = {
    entry: {
        'polyfills': './src/polyfills.ts',
        'vendor': './src/vendor.ts',
        'app': './src/main.ts'
    },
    resolve: {
        extensions: ['.ts', '.tsx', '.js', '.jsx']
    },
    module: {
        rules: [
            {
                test: /\.ts$/,
                loader: 'awesome-typescript-loader'
            },
            {
                test: /\.(html|htm|php)$/,
                loader: 'html-loader'
            },
            {
                test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
                loader: 'file-loader?name=assets/[name].[hash].[ext]'
            },
            {
                test: /\.css$/,
                exclude: helpers.root('src', 'app'),
                loader: ExtractTextPlugin.extract({
                    fallbackLoader: 'style-loader',
                    loader: 'css-loader?sourceMap'
                })
            },
            {
                test: /\.css$/,
                include: helpers.root('src', 'app'),
                loader: 'raw-loader'
            }
        ]
    },
    plugins: [
        // Workaround for angular/angular#11580
        new webpack.ContextReplacementPlugin(
            // The (\\|\/) piece accounts for path separators in *nix and Windows
            /angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
            helpers.root('./src'), // location of your src
            {} // a map of your routes
        ),

        new webpack.optimize.CommonsChunkPlugin({
            name: ['app', 'vendor', 'polyfills']
        }),

        new HtmlWebpackPlugin({
            template: '../../template/base/app.php'
        })

        // new webpack.optimize.UglifyJsPlugin()
    ],
    output: {
        filename: '[name].js'
    }
};
TypeScript(在以默认经典分辨率设置编写时)将自动检测以
.ts
.tsx
结尾的文件,在这些情况下不需要扩展名。根据TypeScript模块解析约定,所有其他文件都需要扩展名:

Tl;博士:
如果包含
A
而没有扩展名类型,脚本将查找
A.ts
A.tsx

我意识到我有两个同名但扩展名不同的文件
notes.js
notes.ts
。当文件名冲突时,可能需要扩展名

Typescript文件的扩展名为.ts。为什么您不想首先创建一个扩展名为.ts的文件?我的文件扩展名为.ts,问题是在未将扩展名放入导入状态的情况下无法加载文件。请与我共享tsconfig?@JoséQuintoZamora tsconfig Addeder您是否使用webpack和ts loader?如果是这样的话,请你也分享你的配置好吗?这就是问题所在,我也这么认为,但不幸的是事实并非如此。未加载.ts文件,即使扩展名正确。在tsconfig中,我尝试了classic和node,但都不起作用。这与classic分辨率无关。在TypeScript中导入带有显式扩展名
.ts
的TypeScript文件是无效的。@donnikitos抱歉,我似乎误解了您的问题。这确实是一种奇怪的行为,我无法解释(你为什么把我标记为答案哈哈)@KevinPei这是为谷歌搜索者准备的。否则就是我的错。。。。其中一个文件具有双*.ts扩展名(可能是在复制一个文件时发生的)