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

[ts] Cannot find module when project rebuild #22349

Closed
mjbvz opened this issue Mar 6, 2018 · 8 comments · Fixed by #23910
Closed

[ts] Cannot find module when project rebuild #22349

mjbvz opened this issue Mar 6, 2018 · 8 comments · Fixed by #23910
Assignees
Labels
Bug A bug in TypeScript Design Limitation Constraints of the existing architecture prevent this from being fixed VS Code Tracked There is a VS Code equivalent to this issue

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Mar 6, 2018

From @STayinloves on February 28, 2018 7:41

  • VSCode Version:
    Version 1.20.1
    Commit f88bbf9137d24d36d968ea6b2911786bfe103002
    Date 2018-02-13T15:34:36.336Z
    Shell 1.7.9
    Renderer 58.0.3029.110
    Node 7.9.0
    Architecture x64
  • OS Version:

Steps to Reproduce:

  1. Clone https://github.com/Microsoft/Recognizers-Text
  2. cd javascript path
  3. run build script
  4. edit a ts file JavaScript/packages/recognizers-number/src/number/parsers.ts for example
  5. error [ts] Cannot find module '@microsoft/recognizers-text'.

reload vscode the error disappears.

rm -rf node_modules
npm run build

can also reproduce this bug.

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

Copied from original issue: microsoft/vscode#44710

@mjbvz mjbvz self-assigned this Mar 6, 2018
@mjbvz mjbvz added VS Code Tracked There is a VS Code equivalent to this issue and removed javascript labels Mar 6, 2018
@mjbvz mjbvz removed their assignment Mar 6, 2018
@mhegazy mhegazy added the Bug A bug in TypeScript label Mar 6, 2018
@mhegazy mhegazy added this to the TypeScript 2.9 milestone Apr 13, 2018
@sheetalkamat
Copy link
Member

@STayinloves can you please try latest vscode version (1.22.1) and provide exact steps if this repros.

In step "3", should i run npm run build or build.cmd in Javascript folder? the npm run build needs some lerna package and installs quite a few files like the file JavaScript/packages/recognizers-number/src/number/parsers.ts you mentioned along with node_modules folders installed in the JavaScript/packages/recognizers-number folders. Editing that file does not generate error about module resolution but deleting the node_modules as intended generates the error.

@sheetalkamat sheetalkamat added the Needs More Info The issue still hasn't been fully clarified label Apr 13, 2018
@mhegazy mhegazy closed this as completed Apr 26, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Apr 26, 2018

closing for now. please reopen if more information is available.

@sanxing-chen
Copy link

sanxing-chen commented Apr 28, 2018

Sorry for overlook this timeline. I'm using the latest version(1.22.2) of VScode now, the error still happens.

@sheetalkamat for your first question, Yes, you should npm run build in the Javascript folder(the builld.cmd has the same effect).

The Lerna tool does "bootstrap" the subprojects run npm run install && npm run prepare(include building the TS projects)

More detail:

My workspace folder is the whole git project which contains.NET, Python, and Javascript.

I think one way can reproduce this error is:

  1. you should open a file in specific subproject like recognizers-date-time first, cite Javascript\packages\recognizers-date-time\src\dateTime\english\dateConfiguration.ts for example. You can see the file import RegExpUtility from "@microsoft/recognizers-text". And there is no error for now.

  2. Then you add a line to the end of file Patterns\English\English-DateTime.yaml. This step is meant to produce some changes in the Javascript, to the recognizers-date-time\src\dateTime\resources.

  3. Then you run npm run build under the folder Javascript.

  4. Wait error occurred in the Javascript\packages\recognizers-date-time\src\dateTime\english\dateConfiguration.ts.

I notice the error always occurred in the subproject I have just made changes to and doesn't happen in the other subprojects. It may because of the pattern file's changes.

pic:
image
image
You can see the recognizer-text package installed correctly under the recognizers-date-time\node_modules folder.

@mhegazy mhegazy reopened this Apr 30, 2018
@sheetalkamat
Copy link
Member

@STayinloves I followed the repro steps you mentioned but wasnt able to reproduce the issue (that is there is no error shown for module resolution). Then when i looked at your initial report, i realised you were trying typescript@2.8, so i tried this with typescript@2.8.3 and was able to repro the issue. The issue is fixed in the master. You can try using typescript@next and see if the issue is fixed for you.
Just for record this is what i did to repro the issue.

cd Javascript
npm install lerna
npm run build
cd ..
code .

Opened Javascript\packages\recognizers-date-time\src\dateTime\english\dateConfiguration.ts and verified it doesnt show error for resolution of @microsoft/recognizer-text
Then with that file open, opened file Patterns\English\English-DateTime.yaml and added below text in the end

SpecialDecade2Cases: !dictionary
  types: [ string, int ]
  entries:
    'noughties2': 2000
    'two thousands2': 2000

On command prompt

cd Javascript
npm run build

After compilation was complete checked the open ts file and if the issue repros you see error about resolution of @microsoft/recognizer-text which is fixed now.

@sheetalkamat sheetalkamat added Fixed A PR has been merged for this issue and removed Needs More Info The issue still hasn't been fully clarified labels Apr 30, 2018
@mhegazy mhegazy closed this as completed Apr 30, 2018
@sanxing-chen
Copy link

sanxing-chen commented May 2, 2018

@sheetalkamat I have updated the typescript version to 2.9.0-dev.20180501 the problem still happens.
I find an easier way to reproduce this problem:

  • build the project by npm run build
  • open one file, cite JavaScript\packages\recognizers-date-time\src\dateTime\baseDate.ts
  • delete the lib folder JavaScript\packages\recognizers-date-time\node_modules\@microsoft\recognizers-text\dist
  • there should be an error occurred in the file we opened previously
  • rebuild the project; we can see the dist folder regenerates
  • reopen the file we opened previously, the error still there

@sanxing-chen
Copy link

@mhegazy Please reopen the issue. I'm sorry for previous misjudge, I have updated the comment above.

@sheetalkamat
Copy link
Member

@STayinloves I was able to track down the issue and have PR to handle these kind of scenario. Unfortunately handling it with the settings you have, isnt feasible from performance perspective since you have a setup such that your node_modules in the JavaScript\packages\recognizers-date-time have symbolic link folder in JavaScript\packages\recognizers-date-time\node_modules\@microsoft which means we cannot just say JavaScript\packages\recognizers-date-time\node_modules\@microsoft\recognizers-text is same as JavaScript\packages\recognizers-text folder without doing costly mapping. The solution to this is adding path mapping to the tsconfig.json. I modified ``JavaScript\packages\recognizers-date-time\tsconfig.json``` to

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es2015",
        "outDir": "compiled",
        "sourceMap": true,
        "rootDir": "src",
        "moduleResolution": "node",
        "declaration": true,
        "declarationDir": "dist/types",
        "typeRoots": [
            "node_modules/@types"
        ],
        "baseUrl": "./", 
        "paths": {
            "@microsoft/recognizers-text-number": ["../recognizers-number"],
            "@microsoft/*": ["../*"]
        }
    },
    "include": [
        "src"
    ]
}

and used drop from #23910 and was able to see that this issue gets resolved. Can you please give that a try as well.

(Note the baseUrl and paths entries and how they help with the resolution. Compiler tries to resolve "@microsoft/recognizers-text-number" to ../recognizers-number before followings its usual course and hence that helps in us having knowledge that the recognizers-number will take part in module resolution and to handle it accordingly.)

@sheetalkamat sheetalkamat added the Fixed A PR has been merged for this issue label May 4, 2018
@sanxing-chen
Copy link

Thank you @sheetalkamat !
I'll bring this up to our team and provide feedback here.

@mhegazy mhegazy added Design Limitation Constraints of the existing architecture prevent this from being fixed and removed Fixed A PR has been merged for this issue labels May 8, 2018
@mhegazy mhegazy closed this as completed May 8, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Design Limitation Constraints of the existing architecture prevent this from being fixed VS Code Tracked There is a VS Code equivalent to this issue
Projects
None yet
4 participants