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

Using typescript from external module results in parsing error #1075

Closed
vigenere23 opened this issue Oct 6, 2020 · 4 comments
Closed

Using typescript from external module results in parsing error #1075

vigenere23 opened this issue Oct 6, 2020 · 4 comments

Comments

@vigenere23
Copy link

Describe the bug

Using typescript inside a Svelte component is fine, except when that file comes from an external module. This bug happens either when an external component using a Typescript file is imported and used or when the external Typescript file itself is directly imported and used.

Additional infos :

  1. the web app project was setup using the provided script
  2. the component library (external package) project was setup using a similar config, although such config is not provided by Svelte
  3. the usage of the component library (external package) is done wither via npm link or by installing from npmjs.

Logs

See stacktraces

To Reproduce

  1. clone app project and install dependencies : https://github.com/vigenere23/svelte-issue-5503
  2. clone component library project and install dependencies : https://github.com/vigenere23/svelte-component-issue-5503
  3. to locally link dependencies :
    1. inside component project, run yarn link
    2. inside app project, run yarn link svelte-component

Expected behavior

I would expect one of the following:

  1. the library component would use an inlined compiled version of the used typescript file
  2. the app project would directly import the typescript file and compile it itself, just like it does for local typescript files

Stacktraces

Stack trace for locally linking dependencies
bundles src/main.ts → public/build/bundle.js...
[!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
../gabio-design-svelte/src/utils/url.ts (1:7)
1: export type RelativeUrlResolver = (relativeUrl: string) => string
        ^
2:
3: export function resolveURL(
Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
  at error (/home/gabio/Documents/projects/gabio-web-svelte/node_modules/rollup/dist/shared/rollup.js:5210:30)
  at Module.error (/home/gabio/Documents/projects/gabio-web-svelte/node_modules/rollup/dist/shared/rollup.js:9725:16)
  at tryParse (/home/gabio/Documents/projects/gabio-web-svelte/node_modules/rollup/dist/shared/rollup.js:9639:23)
  at Module.setSource (/home/gabio/Documents/projects/gabio-web-svelte/node_modules/rollup/dist/shared/rollup.js:10036:30)
  at ModuleLoader.addModuleSource (/home/gabio/Documents/projects/gabio-web-svelte/node_modules/rollup/dist/shared/rollup.js:18178:20)
  at ModuleLoader.fetchModule (/home/gabio/Documents/projects/gabio-web-svelte/node_modules/rollup/dist/shared/rollup.js:18232:9)
  at async Promise.all (index 1)
  at ModuleLoader.fetchStaticDependencies (/home/gabio/Documents/projects/gabio-web-svelte/node_modules/rollup/dist/shared/rollup.js:18256:34)
  at async Promise.all (index 0)
  at ModuleLoader.fetchModule (/home/gabio/Documents/projects/gabio-web-svelte/node_modules/rollup/dist/shared/rollup.js:18233:9)
Stack trace for remotely linking dependencies
src/main.ts → public/build/bundle.js...
[!] (plugin typescript) Error: Could not load /home/gabio/Documents/svelte-typescript-test/node_modules/@vigenere23/svelte-component/src/index.ts (imported by src/App.svelte): Debug Failure. False expression: Expected fileName to be present in command line
Error: Could not load /home/gabio/Documents/svelte-typescript-test/node_modules/@vigenere23/svelte-component/src/index.ts (imported by src/App.svelte): Debug Failure. False expression: Expected fileName to be present in command line
    at Object.getOutputFileNames (/home/gabio/Documents/svelte-typescript-test/node_modules/typescript/lib/typescript.js:94573:18)
    at findTypescriptOutput (/home/gabio/Documents/svelte-typescript-test/node_modules/@rollup/plugin-typescript/dist/index.js:391:33)
    at Object.load (/home/gabio/Documents/svelte-typescript-test/node_modules/@rollup/plugin-typescript/dist/index.js:592:28)

Information about your Svelte project:

  • Browser: agnostic
  • OS: Linux Ubuntu-based 20.04
  • Svelte: 3.29.0 (latest from the time of writing)
  • Rollup (from the given template)

Severity

It is currently blocking my project, and probably any other project that uses typescript component libraries. Starting from scratch in pain JS is possible but that's not the goal.

Additional context

More infos about the bug and temporary fixes here : sveltejs/component-template#29 (comment)

@vigenere23 vigenere23 changed the title Importing typescript from external module results in parsing error Using typescript from external module results in parsing error Oct 6, 2020
@stefanovualto
Copy link

@vigenere23 were you able to find a solution?

@vigenere23
Copy link
Author

@stefanovualto Yes, my template has a working fix inspired from this discussion.

@stale
Copy link

stale bot commented Jun 26, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@pngwn pngwn transferred this issue from sveltejs/svelte Jun 26, 2021
@dummdidumm
Copy link
Member

Closing as this is unrelated to language-tools, this sounds more like a limitation with how the Rollup plugin handles files. In general, you should avoid having typescript files or Svelte files which require preprocessors in your node_modules and instead provide transpiled files along with type definitions. More info: https://github.com/sveltejs/language-tools/blob/master/docs/preprocessors/typescript.md#typing-components-authoring-packages

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

3 participants