2016-11-15 6 views
5

मैं एक साधारण NodeJS एप्लिकेशन का निर्माण करने की कोशिश करते समय त्रुटि मिल गया है:एक आयात पथ '.ts से समाप्त नहीं हो सकता है - NodeJS और दृश्य कोड

enter image description here

यहां तक ​​कि दृश्य कोड एक त्रुटि का संकेत देता है, मेरा कोड चल रहा है .. जब मैं आयात कथन से .ts एक्सटेंशन को हटाता हूं, तो मुझे एक त्रुटि मिली है कि फ़ाइल नहीं मिल सकती है।

मैं वेबपैक का उपयोग कर रहा हूं, लेकिन ये फ़ाइलें सर्वर से हैं।

enter image description here

यहाँ मेरी webpack फ़ाइल है और::

var webpack = require('webpack'); 
 
var helpers = require('./helpers'); 
 

 
//# Webpack Plugins 
 
var CopyWebpackPlugin = (CopyWebpackPlugin = require('copy-webpack-plugin'), CopyWebpackPlugin.default || CopyWebpackPlugin); 
 
const HtmlWebpackPlugin = require('html-webpack-plugin'); 
 
const ForkCheckerPlugin = require('awesome-typescript-loader').ForkCheckerPlugin; 
 
var ExtractTextPlugin = require('extract-text-webpack-plugin'); 
 

 
//# Webpack Constants 
 
const ENV = process.env.ENV = process.env.NODE_ENV = 'development'; 
 
const HMR = helpers.hasProcessFlag('hot'); 
 
const METADATA = { 
 
    title: 'My Application', 
 
    baseUrl: '/', 
 
    host: process.env.HOST || '0.0.0.0', 
 
    port: process.env.PORT || 8080, 
 
    ENV: ENV, 
 
    HMR: HMR 
 
}; 
 

 
//# Webpack Configuration 
 
module.exports = { 
 
    metadata: METADATA, 
 

 
    entry: { 
 
    'polyfills': './src/polyfills.ts', 
 
    'vendor': './src/vendor.ts', 
 
    'main': './src/main.ts', 
 
    }, 
 

 
    resolve: { 
 
    extensions: ['', '.ts', '.tsx', '.js', '.scss'], 
 
    root: helpers.root('src'), 
 
    modulesDirectories: [ 
 
     'node_modules', 
 
     'server' 
 
    ] 
 
    }, 
 

 
    module: { 
 
    preLoaders: [ 
 
     { 
 
     test: /\.js$/, 
 
     loader: 'source-map-loader', 
 
     exclude: [ 
 
      helpers.root('node_modules/rxjs'), 
 
      helpers.root('node_modules/@angular2-material'), 
 
      helpers.root('node_modules/@angular') 
 
     ] 
 
     } 
 

 
    ], 
 

 
    loaders: [ 
 
     { 
 
     test: /\.ts$/, 
 
     loader: 'awesome-typescript-loader', 
 
     exclude: [/\.(spec|e2e)\.ts$/] 
 
     }, 
 
     { 
 
     test: /\.json$/, 
 
     loader: 'json-loader' 
 
     }, 
 
     { 
 
     test: /\.css$/, 
 
     loader: 'raw-loader' 
 
     }, 
 
     { 
 
     test: /\.html$/, 
 
     loader: 'raw-loader', 
 
     exclude: [helpers.root('src/index.html')] 
 
     }, 
 
     { 
 
     test: /\.scss|css$/, 
 
     loader: ExtractTextPlugin.extract({ fallbackLoader: 'style-loader', loader: 'css-loader!sass-loader' }), 
 
     exclude: [ helpers.root('node_modules') ] 
 
     }, 
 
     { 
 
     test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, 
 
     loader: "url-loader?limit=10000&mimetype=application/font-woff" 
 
     }, 
 
     { 
 
     test: /\.(ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/, 
 
     loader : 'file-loader' 
 
     } 
 
    ] 
 
    }, 
 

 
    plugins: [ 
 

 
    new ForkCheckerPlugin(), 
 
    new webpack.optimize.OccurrenceOrderPlugin(true), 
 

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

 
    new ExtractTextPlugin("[name].css"), 
 

 
    new CopyWebpackPlugin([{ 
 
     from: 'src/assets', 
 
     to: 'assets' 
 
    }]), 
 

 
    new HtmlWebpackPlugin({ 
 
     template: 'src/index.html', 
 
     chunksSortMode: 'dependency' 
 
    }), 
 

 
    new webpack.ProvidePlugin({ 
 
     jQuery: 'jquery', 
 
     $: 'jquery', 
 
     jquery: 'jquery', 
 
     "Tether": 'tether', 
 
     "window.Tether": "tether" 
 
    }) 
 

 
    ], 
 
    
 
    node: { 
 
    global: 'window', 
 
    crypto: 'empty', 
 
    module: false, 
 
    clearImmediate: false, 
 
    setImmediate: false 
 
    } 
 
};

किसी को भी मेरी मदद कर सकते यहाँ मेरी फ़ोल्डर संरचना है? टी.के.एस!

+0

एक उदाहरण है [टाइपस्क्रिप्ट वेबसाइट पर] (https://www.typescriptlang.org/docs/handbook/react-&-webpack.html) जो विस्तार के बिना आयात करता है: 'आयात {हैलो} से "./ घटकों/हैलो ",'। शायद यह भविष्य का दृष्टिकोण है? यह काफी परेशान है क्योंकि यह बनाम कोड में इंटेलिजेंस खो गया है ... – NickL

उत्तर

0

मुझे यकीन नहीं है कि इस प्रश्न का सही समाधान क्या है। जाहिर है, समाधान remove the .ts extension — it is a configuration issue if it cannot find the file है। मेरे लिए कॉन्फ़िगरेशन समस्या हल हो गई जब मैंने ts-loader का उपयोग शुरू किया।

संबंधित मुद्दे