Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript: Cannot find module "module-package" or its corresponding type declarations. #54628

Closed
Jastin-Infj opened this issue Jun 8, 2023 · 6 comments

Comments

@Jastin-Infj
Copy link

Jastin-Infj commented Jun 8, 2023

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version:
Version: 1.78.2 (user setup)
Commit: b3e4e68a0bc097f0ae7907b217c1119af9e03435
Date: 2023-05-10T14:39:26.248Z
Electron: 22.5.2
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Windows_NT x64 10.0.22621
Sandboxed: Yes
  • OS Version:
PRETTY_NAME="Ubuntu 22.04.2 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.2 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

Steps to Reproduce:

  1. Install from package.json
  2. Check to see if an "import" has taken place.

Ideal Movement

"lodash" is properly imported.
"js", it imports without problems.

Is there some other way to set up importing in typescript in VsCode?

What we have done so far

Typescript Restart
image

declare module Definition.(Temporary solution)
image

Reinstall package.json

Switched "devDependencies" and "dependencies

Sources

package.json
{
  "name": "None",
  "version": "1.0.0",
  "description": "None",
  "main": "test.tsx",
  "scripts": {
    "build": "webpack --config ./webpack.config.test.js",
    "start": "webpack serve --config ./webpack.config.test.js",
    "tsc": "tsc"
  },
  "author": "",
  "license": "ISC",
  "volta": {
    "node": "18.16.0",
    "npm": "9.5.1",
    "yarn": "4.0.0-rc.45"
  },
  "devDependencies": {
    "@babel/core": "^7.22.1",
    "@babel/plugin-transform-react-jsx": "^7.22.3",
    "@babel/preset-env": "^7.22.4",
    "@babel/preset-react": "^7.22.3",
    "@babel/preset-typescript": "^7.21.5",
    "@types/lodash": "^4.14.195",
    "@types/node": "^20.2.5",
    "babel-loader": "^9.1.2",
    "css-loader": "^6.8.1",
    "file-loader": "^6.2.0",
    "html-loader": "^4.2.0",
    "html-webpack-plugin": "^5.5.1",
    "lodash": "^4.17.21",
    "mini-css-extract-plugin": "^2.7.6",
    "sass": "^1.62.1",
    "sass-loader": "^13.3.1",
    "ts-loader": "^9.4.3",
    "typescript": "^5.1.3",
    "url-loader": "^4.1.1",
    "webpack": "^5.85.0",
    "webpack-cli": "^5.1.1",
    "webpack-dev-server": "^4.15.0"
  },
  "dependencies": {
    "@types/react": "^18.2.9",
    "@types/react-dom": "^18.2.4",
    "axios": "^1.4.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}
webpack.config.test.js
module.exports = {
  mode: "development",
  entry: {
    main: {
      import: './src/frontend/ts/test.tsx',
      dependOn: 'shared'
    },
    shared: ['lodash']
  },
  output: {
    path: `${__dirname}/dist`,
    filename: "[name].js",
  },
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: "ts-loader",
        exclude: /node_modules/
      },
    ],
  },
  resolve: {
    extensions: [".ts", ".tsx", ".js", ".json"],
  },
  target: ["web", "es5"],
  devServer: {
    static: {
      directory: `${__dirname}`
    }
  },
};
tsconfig.json
{
  "compilerOptions": {
    "outDir": "./dist/",
    "noImplicitAny": true,
    "module": "es6",
    "target": "es5",
    "jsx": "react",
    "allowJs": true,
    "moduleResolution": "node",
    "types": [
      "node"
    ],
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true
  }
}

image
image
image

@Jastin-Infj Jastin-Infj changed the title Cannot find module "module-package" or its corresponding type declarations. Typescript Cannot find module "module-package" or its corresponding type declarations. Jun 8, 2023
@Jastin-Infj Jastin-Infj changed the title Typescript Cannot find module "module-package" or its corresponding type declarations. Typescript: Cannot find module "module-package" or its corresponding type declarations. Jun 8, 2023
@devoren
Copy link

devoren commented Jun 8, 2023

same, all my ts code is red and says /unresolved/

@mjbvz
Copy link
Contributor

mjbvz commented Jun 8, 2023

Does this reproduce in the latest VS Code insiders build with all extensions disabled?

@Jastin-Infj
Copy link
Author

Jastin-Infj commented Jun 9, 2023

I removed everything except SSH.
Predictive package conversion and Typescript Restart runserver did not work, but it did work.

image

image

I installed the latest VS Code insiders build.

Only SSH is install.
With SSH already installed, the default configuration looks like this

image
image

@MatheusProtzen
Copy link

Same here, after updated to 1.79.0 it stopped working.
image

@MatheusProtzen
Copy link

I solved it by removing the typeRoots, any idea why?

@mjbvz mjbvz transferred this issue from microsoft/vscode Jun 12, 2023
@mjbvz mjbvz removed their assignment Jun 12, 2023
@Jastin-Infj
Copy link
Author

Jastin-Infj commented Jun 13, 2023

Restarting Vscode after executing the following command worked.
yarn dlx @yarnpkg/sdks vscode

To create a new one

In the directory where package.json is located, do the following
yarn install
yarn dlx @yarnpkg/sdks vscode

Thank you for your time.

For more information, please visit.
yarnpkg/berry#3350

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants