Module not found: Error: Can't resolve './templates'












0















I have this javascript (TypeScript) file



index.ts



import 
'../node_modules/bootstrap/dist/css/bootstrap.min.css';
import 'bootstrap';
import * as templates from './templates';

document.body.innerHTML = templates.main;

const mainElement =
document.body.querySelector('.b4.main');
const alertsElement =
document.body.querySelector('.b4-alerts');

mainElement.innerHTML = templates.welcome;
alertsElement.innerHTML = templates.alert;


When I run my project (with webpack dev server) I get the following error:



Module not found: Error: Can't resolve './templates' in '/Users/BorisGrunwald/Desktop/Node/b4-app/app'


I don't understand why it can't seem to find "templates.ts" since both files are in the same folder.



Here is a picture of my project structure:



enter image description here



My webpack config:



'use strict';

const path = require('path');
const distDir = path.resolve(__dirname,'dist');

const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');

module.exports = {
entry: './app/index.ts',
output: {
filename: 'bundle.js',
path: distDir
},
devServer: {
contentBase:distDir,
port:60800
},
plugins: [
new HtmlWebpackPlugin({
title: 'Better Book Bundle Builder'
}),
new webpack.ProvidePlugin({
$:'jquery',
jQuery:'jquery'
})
],
module: {
rules: [{
test:/.ts$/,
loader:'ts-loader'
},{
test: /.css$/,
use:['style-loader','css-loader']
},{
test: /.(png|woff|woff2|eot|ttf|svg)$/,
loader:'url-loader?limit=100000'
}]
}
};


Templates.ts



export const main = `
<div class="container">
<h1>B4 - Book Bundler</h1>
<div class="b4-alerts"></div>
<div class="b4-main"></div>
</div>
`;

export const welcome = `
<div class="jumbotron">
<h1>Welcome!</h1>
<p>B4 is an application for creating book bndles</p>
</div>
`;

export const alert = `
<div class="alert alert-success alert-dismissible fade in"
role="alert">
<button class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<strong>Success!</strong> Bootstrap is working
</div>
`;


Can anyone see what is wrong?










share|improve this question





























    0















    I have this javascript (TypeScript) file



    index.ts



    import 
    '../node_modules/bootstrap/dist/css/bootstrap.min.css';
    import 'bootstrap';
    import * as templates from './templates';

    document.body.innerHTML = templates.main;

    const mainElement =
    document.body.querySelector('.b4.main');
    const alertsElement =
    document.body.querySelector('.b4-alerts');

    mainElement.innerHTML = templates.welcome;
    alertsElement.innerHTML = templates.alert;


    When I run my project (with webpack dev server) I get the following error:



    Module not found: Error: Can't resolve './templates' in '/Users/BorisGrunwald/Desktop/Node/b4-app/app'


    I don't understand why it can't seem to find "templates.ts" since both files are in the same folder.



    Here is a picture of my project structure:



    enter image description here



    My webpack config:



    'use strict';

    const path = require('path');
    const distDir = path.resolve(__dirname,'dist');

    const HtmlWebpackPlugin = require('html-webpack-plugin');
    const webpack = require('webpack');

    module.exports = {
    entry: './app/index.ts',
    output: {
    filename: 'bundle.js',
    path: distDir
    },
    devServer: {
    contentBase:distDir,
    port:60800
    },
    plugins: [
    new HtmlWebpackPlugin({
    title: 'Better Book Bundle Builder'
    }),
    new webpack.ProvidePlugin({
    $:'jquery',
    jQuery:'jquery'
    })
    ],
    module: {
    rules: [{
    test:/.ts$/,
    loader:'ts-loader'
    },{
    test: /.css$/,
    use:['style-loader','css-loader']
    },{
    test: /.(png|woff|woff2|eot|ttf|svg)$/,
    loader:'url-loader?limit=100000'
    }]
    }
    };


    Templates.ts



    export const main = `
    <div class="container">
    <h1>B4 - Book Bundler</h1>
    <div class="b4-alerts"></div>
    <div class="b4-main"></div>
    </div>
    `;

    export const welcome = `
    <div class="jumbotron">
    <h1>Welcome!</h1>
    <p>B4 is an application for creating book bndles</p>
    </div>
    `;

    export const alert = `
    <div class="alert alert-success alert-dismissible fade in"
    role="alert">
    <button class="close" data-dismiss="alert" aria-label="Close">
    <span aria-hidden="true">&times;</span>
    </button>
    <strong>Success!</strong> Bootstrap is working
    </div>
    `;


    Can anyone see what is wrong?










    share|improve this question



























      0












      0








      0


      0






      I have this javascript (TypeScript) file



      index.ts



      import 
      '../node_modules/bootstrap/dist/css/bootstrap.min.css';
      import 'bootstrap';
      import * as templates from './templates';

      document.body.innerHTML = templates.main;

      const mainElement =
      document.body.querySelector('.b4.main');
      const alertsElement =
      document.body.querySelector('.b4-alerts');

      mainElement.innerHTML = templates.welcome;
      alertsElement.innerHTML = templates.alert;


      When I run my project (with webpack dev server) I get the following error:



      Module not found: Error: Can't resolve './templates' in '/Users/BorisGrunwald/Desktop/Node/b4-app/app'


      I don't understand why it can't seem to find "templates.ts" since both files are in the same folder.



      Here is a picture of my project structure:



      enter image description here



      My webpack config:



      'use strict';

      const path = require('path');
      const distDir = path.resolve(__dirname,'dist');

      const HtmlWebpackPlugin = require('html-webpack-plugin');
      const webpack = require('webpack');

      module.exports = {
      entry: './app/index.ts',
      output: {
      filename: 'bundle.js',
      path: distDir
      },
      devServer: {
      contentBase:distDir,
      port:60800
      },
      plugins: [
      new HtmlWebpackPlugin({
      title: 'Better Book Bundle Builder'
      }),
      new webpack.ProvidePlugin({
      $:'jquery',
      jQuery:'jquery'
      })
      ],
      module: {
      rules: [{
      test:/.ts$/,
      loader:'ts-loader'
      },{
      test: /.css$/,
      use:['style-loader','css-loader']
      },{
      test: /.(png|woff|woff2|eot|ttf|svg)$/,
      loader:'url-loader?limit=100000'
      }]
      }
      };


      Templates.ts



      export const main = `
      <div class="container">
      <h1>B4 - Book Bundler</h1>
      <div class="b4-alerts"></div>
      <div class="b4-main"></div>
      </div>
      `;

      export const welcome = `
      <div class="jumbotron">
      <h1>Welcome!</h1>
      <p>B4 is an application for creating book bndles</p>
      </div>
      `;

      export const alert = `
      <div class="alert alert-success alert-dismissible fade in"
      role="alert">
      <button class="close" data-dismiss="alert" aria-label="Close">
      <span aria-hidden="true">&times;</span>
      </button>
      <strong>Success!</strong> Bootstrap is working
      </div>
      `;


      Can anyone see what is wrong?










      share|improve this question
















      I have this javascript (TypeScript) file



      index.ts



      import 
      '../node_modules/bootstrap/dist/css/bootstrap.min.css';
      import 'bootstrap';
      import * as templates from './templates';

      document.body.innerHTML = templates.main;

      const mainElement =
      document.body.querySelector('.b4.main');
      const alertsElement =
      document.body.querySelector('.b4-alerts');

      mainElement.innerHTML = templates.welcome;
      alertsElement.innerHTML = templates.alert;


      When I run my project (with webpack dev server) I get the following error:



      Module not found: Error: Can't resolve './templates' in '/Users/BorisGrunwald/Desktop/Node/b4-app/app'


      I don't understand why it can't seem to find "templates.ts" since both files are in the same folder.



      Here is a picture of my project structure:



      enter image description here



      My webpack config:



      'use strict';

      const path = require('path');
      const distDir = path.resolve(__dirname,'dist');

      const HtmlWebpackPlugin = require('html-webpack-plugin');
      const webpack = require('webpack');

      module.exports = {
      entry: './app/index.ts',
      output: {
      filename: 'bundle.js',
      path: distDir
      },
      devServer: {
      contentBase:distDir,
      port:60800
      },
      plugins: [
      new HtmlWebpackPlugin({
      title: 'Better Book Bundle Builder'
      }),
      new webpack.ProvidePlugin({
      $:'jquery',
      jQuery:'jquery'
      })
      ],
      module: {
      rules: [{
      test:/.ts$/,
      loader:'ts-loader'
      },{
      test: /.css$/,
      use:['style-loader','css-loader']
      },{
      test: /.(png|woff|woff2|eot|ttf|svg)$/,
      loader:'url-loader?limit=100000'
      }]
      }
      };


      Templates.ts



      export const main = `
      <div class="container">
      <h1>B4 - Book Bundler</h1>
      <div class="b4-alerts"></div>
      <div class="b4-main"></div>
      </div>
      `;

      export const welcome = `
      <div class="jumbotron">
      <h1>Welcome!</h1>
      <p>B4 is an application for creating book bndles</p>
      </div>
      `;

      export const alert = `
      <div class="alert alert-success alert-dismissible fade in"
      role="alert">
      <button class="close" data-dismiss="alert" aria-label="Close">
      <span aria-hidden="true">&times;</span>
      </button>
      <strong>Success!</strong> Bootstrap is working
      </div>
      `;


      Can anyone see what is wrong?







      javascript typescript webpack






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 16 '18 at 8:23







      Boris Grunwald

















      asked Nov 15 '18 at 19:38









      Boris GrunwaldBoris Grunwald

      453412




      453412
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Try if this works:



          import {main, welcome, alert} from './templates';



          Webpack does not look for .ts files by default. You can configure resolve.extensions to look for .ts. Don't forget to add the default values as well, otherwise most modules will break because they rely on the fact that the .js extension is automatically used.



          resolve: {
          extensions: ['.ts', '.js', '.json']
          }





          share|improve this answer


























          • Didn't work unfortunately.

            – Boris Grunwald
            Nov 15 '18 at 20:19











          • Can you try import * as templates from './templates.ts';

            – gatsbyz
            Nov 15 '18 at 20:23











          • That was it! Really weird since webstorm is giving me the error "TS2691: An import path cannot end with a '.ts' extension. Consider importing './templates' instead"

            – Boris Grunwald
            Nov 15 '18 at 20:27











          • @BorisGrunwald recheck my answer

            – gatsbyz
            Nov 15 '18 at 20:28






          • 1





            Also works in the original way I forgot to add.

            – Boris Grunwald
            Nov 15 '18 at 20:35











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326801%2fmodule-not-found-error-cant-resolve-templates%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Try if this works:



          import {main, welcome, alert} from './templates';



          Webpack does not look for .ts files by default. You can configure resolve.extensions to look for .ts. Don't forget to add the default values as well, otherwise most modules will break because they rely on the fact that the .js extension is automatically used.



          resolve: {
          extensions: ['.ts', '.js', '.json']
          }





          share|improve this answer


























          • Didn't work unfortunately.

            – Boris Grunwald
            Nov 15 '18 at 20:19











          • Can you try import * as templates from './templates.ts';

            – gatsbyz
            Nov 15 '18 at 20:23











          • That was it! Really weird since webstorm is giving me the error "TS2691: An import path cannot end with a '.ts' extension. Consider importing './templates' instead"

            – Boris Grunwald
            Nov 15 '18 at 20:27











          • @BorisGrunwald recheck my answer

            – gatsbyz
            Nov 15 '18 at 20:28






          • 1





            Also works in the original way I forgot to add.

            – Boris Grunwald
            Nov 15 '18 at 20:35
















          1














          Try if this works:



          import {main, welcome, alert} from './templates';



          Webpack does not look for .ts files by default. You can configure resolve.extensions to look for .ts. Don't forget to add the default values as well, otherwise most modules will break because they rely on the fact that the .js extension is automatically used.



          resolve: {
          extensions: ['.ts', '.js', '.json']
          }





          share|improve this answer


























          • Didn't work unfortunately.

            – Boris Grunwald
            Nov 15 '18 at 20:19











          • Can you try import * as templates from './templates.ts';

            – gatsbyz
            Nov 15 '18 at 20:23











          • That was it! Really weird since webstorm is giving me the error "TS2691: An import path cannot end with a '.ts' extension. Consider importing './templates' instead"

            – Boris Grunwald
            Nov 15 '18 at 20:27











          • @BorisGrunwald recheck my answer

            – gatsbyz
            Nov 15 '18 at 20:28






          • 1





            Also works in the original way I forgot to add.

            – Boris Grunwald
            Nov 15 '18 at 20:35














          1












          1








          1







          Try if this works:



          import {main, welcome, alert} from './templates';



          Webpack does not look for .ts files by default. You can configure resolve.extensions to look for .ts. Don't forget to add the default values as well, otherwise most modules will break because they rely on the fact that the .js extension is automatically used.



          resolve: {
          extensions: ['.ts', '.js', '.json']
          }





          share|improve this answer















          Try if this works:



          import {main, welcome, alert} from './templates';



          Webpack does not look for .ts files by default. You can configure resolve.extensions to look for .ts. Don't forget to add the default values as well, otherwise most modules will break because they rely on the fact that the .js extension is automatically used.



          resolve: {
          extensions: ['.ts', '.js', '.json']
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 15 '18 at 20:27

























          answered Nov 15 '18 at 20:16









          gatsbyzgatsbyz

          218317




          218317













          • Didn't work unfortunately.

            – Boris Grunwald
            Nov 15 '18 at 20:19











          • Can you try import * as templates from './templates.ts';

            – gatsbyz
            Nov 15 '18 at 20:23











          • That was it! Really weird since webstorm is giving me the error "TS2691: An import path cannot end with a '.ts' extension. Consider importing './templates' instead"

            – Boris Grunwald
            Nov 15 '18 at 20:27











          • @BorisGrunwald recheck my answer

            – gatsbyz
            Nov 15 '18 at 20:28






          • 1





            Also works in the original way I forgot to add.

            – Boris Grunwald
            Nov 15 '18 at 20:35



















          • Didn't work unfortunately.

            – Boris Grunwald
            Nov 15 '18 at 20:19











          • Can you try import * as templates from './templates.ts';

            – gatsbyz
            Nov 15 '18 at 20:23











          • That was it! Really weird since webstorm is giving me the error "TS2691: An import path cannot end with a '.ts' extension. Consider importing './templates' instead"

            – Boris Grunwald
            Nov 15 '18 at 20:27











          • @BorisGrunwald recheck my answer

            – gatsbyz
            Nov 15 '18 at 20:28






          • 1





            Also works in the original way I forgot to add.

            – Boris Grunwald
            Nov 15 '18 at 20:35

















          Didn't work unfortunately.

          – Boris Grunwald
          Nov 15 '18 at 20:19





          Didn't work unfortunately.

          – Boris Grunwald
          Nov 15 '18 at 20:19













          Can you try import * as templates from './templates.ts';

          – gatsbyz
          Nov 15 '18 at 20:23





          Can you try import * as templates from './templates.ts';

          – gatsbyz
          Nov 15 '18 at 20:23













          That was it! Really weird since webstorm is giving me the error "TS2691: An import path cannot end with a '.ts' extension. Consider importing './templates' instead"

          – Boris Grunwald
          Nov 15 '18 at 20:27





          That was it! Really weird since webstorm is giving me the error "TS2691: An import path cannot end with a '.ts' extension. Consider importing './templates' instead"

          – Boris Grunwald
          Nov 15 '18 at 20:27













          @BorisGrunwald recheck my answer

          – gatsbyz
          Nov 15 '18 at 20:28





          @BorisGrunwald recheck my answer

          – gatsbyz
          Nov 15 '18 at 20:28




          1




          1





          Also works in the original way I forgot to add.

          – Boris Grunwald
          Nov 15 '18 at 20:35





          Also works in the original way I forgot to add.

          – Boris Grunwald
          Nov 15 '18 at 20:35




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326801%2fmodule-not-found-error-cant-resolve-templates%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Bressuire

          Vorschmack

          Quarantine