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

watch mode error for non-TS files (Handlebars, Vue) #32

Closed
mohd-akram opened this issue Sep 23, 2017 · 22 comments
Closed

watch mode error for non-TS files (Handlebars, Vue) #32

mohd-akram opened this issue Sep 23, 2017 · 22 comments
Assignees
Labels
kind: bug Something isn't working properly scope: watch mode Related to Rollup's watch mode

Comments

@mohd-akram
Copy link

I import Handlebars template files which should be ignored by the diagnostics.

Error: Could not find file: '/Users/mohamed/project/src/Views/Shared/spaces.hbs'.
    at getValidSourceFile (/Users/mohamed/project/node_modules/typescript/lib/typescript.js:91281:23)
    at Object.getSyntacticDiagnostics (/Users/mohamed/project/node_modules/typescript/lib/typescript.js:91504:52)
    at /Users/mohamed/project/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:629:74
    at /Users/mohamed/project/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:325:80
    at arrayEach (/Users/mohamed/project/node_modules/rollup-plugin-typescript2/node_modules/lodash/lodash.js:537:11)
    at Function.forEach (/Users/mohamed/project/node_modules/rollup-plugin-typescript2/node_modules/lodash/lodash.js:9359:14)
    at TsCache.walkTree (/Users/mohamed/project/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:325:9)
    at Object.ongenerate (/Users/mohamed/project/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:628:17)
    at bundle.plugins.forEach.plugin (/Users/mohamed/project/node_modules/rollup/dist/rollup.js:10507:16)
    at Array.forEach (<anonymous>)
@ezolenko ezolenko self-assigned this Sep 23, 2017
@ezolenko
Copy link
Owner

Do you import them? Does it happen in non-watch build? Could you post your rollup config and tsconfig.json?

@mohd-akram
Copy link
Author

I do import them like so:

import template from '../Views/Shared/ads.hbs';

with declaration elsewhere:

declare module '*.hbs' {
  export default function (context: any): string;
}

It doesn't happen in a non-watch build.

rollup.config.js:

import commonjs from 'rollup-plugin-commonjs';
import handlebars from 'rollup-plugin-handlebars-plus';
import json from 'rollup-plugin-json';
import resolve from 'rollup-plugin-node-resolve';
import rootImport from 'rollup-plugin-root-import';
import typescript from 'rollup-plugin-typescript2';
import uglify from 'rollup-plugin-uglify';

const partialRoot = `${__dirname}/src/Views/Shared`;

export default {
  output: {
    format: 'iife'
  },
  plugins: [
    typescript({ clean: true }),
    json(),
    resolve(),
    commonjs(),
    rootImport({ root: partialRoot }),
    handlebars({
      helpers: '../../ts/handlebars',
      partialRoot: partialRoot,
      isPartial: () => true
    }),
    uglify()
  ]
}

tsconfig.json

{
  "compilerOptions": {
    "downlevelIteration": true,
    "lib": [
      "dom",
      "dom.iterable",
      "es2017"
    ],
    "moduleResolution": "node",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "strict": true,
    "target": "es5"
  }
}

@ezolenko
Copy link
Owner

I'm tempted to blame this on handlebars plugin, but just looking at the code I can't tell why it would be failing this way. Is it possible to reduce the problem to a small self-contained repo?

@mohd-akram
Copy link
Author

From the stack trace it seems that the TypeScript library is not recognizing it as a valid source file (which it isn't). Perhaps you could skip non-TypeScript files when walking the tree? I'll try to come up with a smaller example.

@ezolenko
Copy link
Owner

Yeah, I already skip non-typescript files by default, but this is typescript trying to parse typescript file and not finding one of the imports. Every watch round the plugin grabs diagnostics for all typescript files, not just the ones modified in that round. This likely have something to do with the error. Does spaces.hbs exist in that path normally, or is that a build artifact?

@mohd-akram
Copy link
Author

Adding a .ts extension fixes it:

helpers: '../../ts/handlebars.ts',

Not sure why this only happens in watch mode. I've created a small repo. Use npm run build or npm run watch.

@ezolenko
Copy link
Owner

Can't reproduce on your repo. Did npm install then npm run watch (successful build), modified main.ts and watch did another successful build. Introducing and fixing an error also works as expected. Running watch after build also works.

Running on windows, package.json didn't have typescript set, so it picked up version 2.5.2 installed with vscode.

Is there something specific I need to do to trigger it?

@mohd-akram
Copy link
Author

The handlebars plugin wasn't working on Windows by default, seems there's a bug in it. I've modified the repo to bypass that and now you should be able to reproduce it.

ezolenko added a commit that referenced this issue Sep 27, 2017
- fix for typescript typing changes
@ezolenko
Copy link
Owner

Heh, you are right, it was trying to load and parse .hbs file.

Try now with master branch

@mohd-akram
Copy link
Author

Hah, yeah it seems fine now :D

@hiendv
Copy link

hiendv commented Nov 14, 2018

Well, I'm experiencing the issue with Vue components. Here's the stack trace.

[!] (rpt2 plugin) Error: Could not find file: '/my/path/src/components/Dashboard.vue?rollup-plugin-vue=script.ts'.
Error: Could not find file: '/my/path/src/components/Dashboard.vue?rollup-plugin-vue=script.ts'.

at getValidSourceFile (/my/path/node_modules/typescript/lib/typescript.js:114851:23)
at Object.getSyntacticDiagnostics (/my/path/node_modules/typescript/lib/typescript.js:115044:52)
at cache.walkTree (/my/path/node_modules/rollup-plugin-typescript2/src/index.ts:282:43)
at lodash_2 (/my/path/node_modules/rollup-plugin-typescript2/src/tscache.ts:174:61)

node: v10.13.0
typescript: v3.1.6

@hiendv
Copy link

hiendv commented Nov 14, 2018

And yes, only in the watch mode.

@ezolenko
Copy link
Owner

@hiendv do you use latest versions of vue plugin and this plugin?

@hiendv
Copy link

hiendv commented Nov 15, 2018

Yes, I do.
Maybe it's irrelevant but I try allowNonTsExtensions and it stays quite for a while :/ Does not work after a while

@ezolenko
Copy link
Owner

@hiendv could you make a minimal repo with reproduction?

@ezolenko ezolenko reopened this Nov 15, 2018
@hiendv
Copy link

hiendv commented Nov 16, 2018

I'm on it but it's kinda hard because of the random appearance of the error.

@hiendv
Copy link

hiendv commented Nov 19, 2018

@ezolenko @ezolenko2 Could you look at this? Thanks. https://github.com/hiendv/rpt2-vue-issue-32

Edit 1: Add a screen cast
peek

ezolenko added a commit that referenced this issue Dec 3, 2018
@ezolenko
Copy link
Owner

ezolenko commented Dec 3, 2018

Ok, finally got around to it, @hiendv could you check if master works for you?

@hiendv
Copy link

hiendv commented Dec 5, 2018

I've been testing the master branch for a while. So far so good. I think this is it. Thank you :D

@hiendv
Copy link

hiendv commented Dec 7, 2018

It's been two days. Everything is fine. I think you can release the patch now. Thank you.

@ezolenko
Copy link
Owner

ezolenko commented Dec 11, 2018

In 0.18.1 now

@hiendv
Copy link

hiendv commented Dec 11, 2018

Thank you.

@agilgur5 agilgur5 changed the title Errors in watch mode for non-TypeScript files Errors in watch mode for non-TS files (Handlebars, Vue) May 26, 2022
Repository owner locked as resolved and limited conversation to collaborators May 26, 2022
@agilgur5 agilgur5 changed the title Errors in watch mode for non-TS files (Handlebars, Vue) watch mode error for non-TS files (Handlebars, Vue) May 26, 2022
@agilgur5 agilgur5 added the scope: watch mode Related to Rollup's watch mode label Jun 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind: bug Something isn't working properly scope: watch mode Related to Rollup's watch mode
Projects
None yet
Development

No branches or pull requests

4 participants