Cannot find module 'path'
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
add a comment |
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
3
Did you runnpm install --save path
?
– mhatch
Mar 15 '18 at 19:04
@mhatchpath
is a global module in node which is available by default
– deadcoder0904
Mar 16 '18 at 9:23
add a comment |
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
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
javascript typescript webpack
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 runnpm install --save path
?
– mhatch
Mar 15 '18 at 19:04
@mhatchpath
is a global module in node which is available by default
– deadcoder0904
Mar 16 '18 at 9:23
add a comment |
3
Did you runnpm install --save path
?
– mhatch
Mar 15 '18 at 19:04
@mhatchpath
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
add a comment |
3 Answers
3
active
oldest
votes
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
add a comment |
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');
add a comment |
This should help
npm i @types/node -D
Typescript needs typings for any module, except if that module is not written in typescript.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered Mar 16 '18 at 9:26
deadcoder0904deadcoder0904
776540
776540
add a comment |
add a comment |
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');
add a comment |
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');
add a comment |
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');
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');
answered Nov 15 '18 at 4:10
vipul patelvipul patel
212
212
add a comment |
add a comment |
This should help
npm i @types/node -D
Typescript needs typings for any module, except if that module is not written in typescript.
add a comment |
This should help
npm i @types/node -D
Typescript needs typings for any module, except if that module is not written in typescript.
add a comment |
This should help
npm i @types/node -D
Typescript needs typings for any module, except if that module is not written in typescript.
This should help
npm i @types/node -D
Typescript needs typings for any module, except if that module is not written in typescript.
answered Nov 15 '18 at 4:13
Nurbol AlpysbayevNurbol Alpysbayev
4,6531432
4,6531432
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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