Cannot find module 'path'










0















I'm attempting to learn Typescript and thought I should also make my webpack config in .ts. This is my webpack.config.ts:



import * as webpack from 'webpack';
import * as path from 'path';

const config: webpack.Configuration =
entry: path.resolve('src/main.ts'),

module:
rules: [

test: /.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/

]
,

resolve:
extensions: ['.tsx', '.ts', '.js']
,

output:
filename: 'index.js',
path: path.resolve( 'dist')



export default config;


As well as my package.json:



 "main": "index.js",
"scripts":
"prebuild": "rimraf dist",
"build": "webpack --config devtools/webpack.config.ts --display-error-details",
"post-build": "webpack-dev-server --config devtools/webpack.config.ts --mode development"
,
"author": "",
"license": "ISC",
"devDependencies":
"ts-loader": "^4.0.1",
"ts-node": "^5.0.1",
"typescript": "^2.7.2",
"webpack": "^4.1.1",
"webpack-cli": "^2.0.12",
"webpack-dev-server": "^3.1.1"

}


The error I get when running npm run build is:



TS2307: Cannot find module 'path'


I have also tried requiring path, but then I get a different error saying it cant find module require.



What seems to be the issue?










share|improve this question



















  • 3





    Did you run npm install --save path?

    – mhatch
    Mar 15 '18 at 19:04











  • @mhatch path is a global module in node which is available by default

    – deadcoder0904
    Mar 16 '18 at 9:23















0















I'm attempting to learn Typescript and thought I should also make my webpack config in .ts. This is my webpack.config.ts:



import * as webpack from 'webpack';
import * as path from 'path';

const config: webpack.Configuration =
entry: path.resolve('src/main.ts'),

module:
rules: [

test: /.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/

]
,

resolve:
extensions: ['.tsx', '.ts', '.js']
,

output:
filename: 'index.js',
path: path.resolve( 'dist')



export default config;


As well as my package.json:



 "main": "index.js",
"scripts":
"prebuild": "rimraf dist",
"build": "webpack --config devtools/webpack.config.ts --display-error-details",
"post-build": "webpack-dev-server --config devtools/webpack.config.ts --mode development"
,
"author": "",
"license": "ISC",
"devDependencies":
"ts-loader": "^4.0.1",
"ts-node": "^5.0.1",
"typescript": "^2.7.2",
"webpack": "^4.1.1",
"webpack-cli": "^2.0.12",
"webpack-dev-server": "^3.1.1"

}


The error I get when running npm run build is:



TS2307: Cannot find module 'path'


I have also tried requiring path, but then I get a different error saying it cant find module require.



What seems to be the issue?










share|improve this question



















  • 3





    Did you run npm install --save path?

    – mhatch
    Mar 15 '18 at 19:04











  • @mhatch path is a global module in node which is available by default

    – deadcoder0904
    Mar 16 '18 at 9:23













0












0








0


1






I'm attempting to learn Typescript and thought I should also make my webpack config in .ts. This is my webpack.config.ts:



import * as webpack from 'webpack';
import * as path from 'path';

const config: webpack.Configuration =
entry: path.resolve('src/main.ts'),

module:
rules: [

test: /.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/

]
,

resolve:
extensions: ['.tsx', '.ts', '.js']
,

output:
filename: 'index.js',
path: path.resolve( 'dist')



export default config;


As well as my package.json:



 "main": "index.js",
"scripts":
"prebuild": "rimraf dist",
"build": "webpack --config devtools/webpack.config.ts --display-error-details",
"post-build": "webpack-dev-server --config devtools/webpack.config.ts --mode development"
,
"author": "",
"license": "ISC",
"devDependencies":
"ts-loader": "^4.0.1",
"ts-node": "^5.0.1",
"typescript": "^2.7.2",
"webpack": "^4.1.1",
"webpack-cli": "^2.0.12",
"webpack-dev-server": "^3.1.1"

}


The error I get when running npm run build is:



TS2307: Cannot find module 'path'


I have also tried requiring path, but then I get a different error saying it cant find module require.



What seems to be the issue?










share|improve this question
















I'm attempting to learn Typescript and thought I should also make my webpack config in .ts. This is my webpack.config.ts:



import * as webpack from 'webpack';
import * as path from 'path';

const config: webpack.Configuration =
entry: path.resolve('src/main.ts'),

module:
rules: [

test: /.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/

]
,

resolve:
extensions: ['.tsx', '.ts', '.js']
,

output:
filename: 'index.js',
path: path.resolve( 'dist')



export default config;


As well as my package.json:



 "main": "index.js",
"scripts":
"prebuild": "rimraf dist",
"build": "webpack --config devtools/webpack.config.ts --display-error-details",
"post-build": "webpack-dev-server --config devtools/webpack.config.ts --mode development"
,
"author": "",
"license": "ISC",
"devDependencies":
"ts-loader": "^4.0.1",
"ts-node": "^5.0.1",
"typescript": "^2.7.2",
"webpack": "^4.1.1",
"webpack-cli": "^2.0.12",
"webpack-dev-server": "^3.1.1"

}


The error I get when running npm run build is:



TS2307: Cannot find module 'path'


I have also tried requiring path, but then I get a different error saying it cant find module require.



What seems to be the issue?







javascript typescript webpack






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 15 '18 at 19:15









mhatch

2,67552346




2,67552346










asked Mar 15 '18 at 19:00









As above so belowAs above so below

8410




8410







  • 3





    Did you run npm install --save path?

    – mhatch
    Mar 15 '18 at 19:04











  • @mhatch path is a global module in node which is available by default

    – deadcoder0904
    Mar 16 '18 at 9:23












  • 3





    Did you run npm install --save path?

    – mhatch
    Mar 15 '18 at 19:04











  • @mhatch path is a global module in node which is available by default

    – deadcoder0904
    Mar 16 '18 at 9:23







3




3





Did you run npm install --save path?

– mhatch
Mar 15 '18 at 19:04





Did you run npm install --save path?

– mhatch
Mar 15 '18 at 19:04













@mhatch path is a global module in node which is available by default

– deadcoder0904
Mar 16 '18 at 9:23





@mhatch path is a global module in node which is available by default

– deadcoder0904
Mar 16 '18 at 9:23












3 Answers
3






active

oldest

votes


















0














Try using require syntax rather than import & change webpack.config.ts to the following code



webpack.config.ts



const webpack = require('webpack');
const path = require('path');

const config: webpack.Configuration =
entry: path.resolve('src/main.ts'),

module:
rules: [

test: /.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/

]
,

resolve:
extensions: ['.tsx', '.ts', '.js']
,

output:
filename: 'index.js',
path: path.resolve( 'dist')



module.exports = config;


And then run npm run build






share|improve this answer






























    0














    First of all no need of .ts extension for webpack config file. Its just internal purpose for building the bundle. Use normal .js file.



    Webpack is not ran by browser, its by Node Js which runs webpack module and make bundle as per config.



    Now Node Js understand its own module system is which is require



    So it would be like below: require in below is Node Js module importing syntax.



    const webpack = require('webpack');
    const path = require('path');





    share|improve this answer






























      0














      This should help



      npm i @types/node -D


      Typescript needs typings for any module, except if that module is not written in typescript.






      share|improve this answer






















        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%2f49307319%2fcannot-find-module-path%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        0














        Try using require syntax rather than import & change webpack.config.ts to the following code



        webpack.config.ts



        const webpack = require('webpack');
        const path = require('path');

        const config: webpack.Configuration =
        entry: path.resolve('src/main.ts'),

        module:
        rules: [

        test: /.tsx?$/,
        use: 'ts-loader',
        exclude: /node_modules/

        ]
        ,

        resolve:
        extensions: ['.tsx', '.ts', '.js']
        ,

        output:
        filename: 'index.js',
        path: path.resolve( 'dist')



        module.exports = config;


        And then run npm run build






        share|improve this answer



























          0














          Try using require syntax rather than import & change webpack.config.ts to the following code



          webpack.config.ts



          const webpack = require('webpack');
          const path = require('path');

          const config: webpack.Configuration =
          entry: path.resolve('src/main.ts'),

          module:
          rules: [

          test: /.tsx?$/,
          use: 'ts-loader',
          exclude: /node_modules/

          ]
          ,

          resolve:
          extensions: ['.tsx', '.ts', '.js']
          ,

          output:
          filename: 'index.js',
          path: path.resolve( 'dist')



          module.exports = config;


          And then run npm run build






          share|improve this answer

























            0












            0








            0







            Try using require syntax rather than import & change webpack.config.ts to the following code



            webpack.config.ts



            const webpack = require('webpack');
            const path = require('path');

            const config: webpack.Configuration =
            entry: path.resolve('src/main.ts'),

            module:
            rules: [

            test: /.tsx?$/,
            use: 'ts-loader',
            exclude: /node_modules/

            ]
            ,

            resolve:
            extensions: ['.tsx', '.ts', '.js']
            ,

            output:
            filename: 'index.js',
            path: path.resolve( 'dist')



            module.exports = config;


            And then run npm run build






            share|improve this answer













            Try using require syntax rather than import & change webpack.config.ts to the following code



            webpack.config.ts



            const webpack = require('webpack');
            const path = require('path');

            const config: webpack.Configuration =
            entry: path.resolve('src/main.ts'),

            module:
            rules: [

            test: /.tsx?$/,
            use: 'ts-loader',
            exclude: /node_modules/

            ]
            ,

            resolve:
            extensions: ['.tsx', '.ts', '.js']
            ,

            output:
            filename: 'index.js',
            path: path.resolve( 'dist')



            module.exports = config;


            And then run npm run build







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 16 '18 at 9:26









            deadcoder0904deadcoder0904

            776540




            776540























                0














                First of all no need of .ts extension for webpack config file. Its just internal purpose for building the bundle. Use normal .js file.



                Webpack is not ran by browser, its by Node Js which runs webpack module and make bundle as per config.



                Now Node Js understand its own module system is which is require



                So it would be like below: require in below is Node Js module importing syntax.



                const webpack = require('webpack');
                const path = require('path');





                share|improve this answer



























                  0














                  First of all no need of .ts extension for webpack config file. Its just internal purpose for building the bundle. Use normal .js file.



                  Webpack is not ran by browser, its by Node Js which runs webpack module and make bundle as per config.



                  Now Node Js understand its own module system is which is require



                  So it would be like below: require in below is Node Js module importing syntax.



                  const webpack = require('webpack');
                  const path = require('path');





                  share|improve this answer

























                    0












                    0








                    0







                    First of all no need of .ts extension for webpack config file. Its just internal purpose for building the bundle. Use normal .js file.



                    Webpack is not ran by browser, its by Node Js which runs webpack module and make bundle as per config.



                    Now Node Js understand its own module system is which is require



                    So it would be like below: require in below is Node Js module importing syntax.



                    const webpack = require('webpack');
                    const path = require('path');





                    share|improve this answer













                    First of all no need of .ts extension for webpack config file. Its just internal purpose for building the bundle. Use normal .js file.



                    Webpack is not ran by browser, its by Node Js which runs webpack module and make bundle as per config.



                    Now Node Js understand its own module system is which is require



                    So it would be like below: require in below is Node Js module importing syntax.



                    const webpack = require('webpack');
                    const path = require('path');






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 15 '18 at 4:10









                    vipul patelvipul patel

                    212




                    212





















                        0














                        This should help



                        npm i @types/node -D


                        Typescript needs typings for any module, except if that module is not written in typescript.






                        share|improve this answer



























                          0














                          This should help



                          npm i @types/node -D


                          Typescript needs typings for any module, except if that module is not written in typescript.






                          share|improve this answer

























                            0












                            0








                            0







                            This should help



                            npm i @types/node -D


                            Typescript needs typings for any module, except if that module is not written in typescript.






                            share|improve this answer













                            This should help



                            npm i @types/node -D


                            Typescript needs typings for any module, except if that module is not written in typescript.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 15 '18 at 4:13









                            Nurbol AlpysbayevNurbol Alpysbayev

                            4,6531432




                            4,6531432



























                                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%2f49307319%2fcannot-find-module-path%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







                                這個網誌中的熱門文章

                                How to read a connectionString WITH PROVIDER in .NET Core?

                                In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

                                Museum of Modern and Contemporary Art of Trento and Rovereto