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

rollup typescript issue when building tooling/api on windows #1699

Closed
BenoitRanque opened this issue May 4, 2021 · 2 comments
Closed

rollup typescript issue when building tooling/api on windows #1699

BenoitRanque opened this issue May 4, 2021 · 2 comments

Comments

@BenoitRanque
Copy link
Contributor

I am having trouble building tooling/api on windows.

[!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)

Full Error
PS C:\Users\ASUS\dev\tauri\tooling\api> yarn build
yarn run v1.22.10
$ rimraf ./dist && rollup -c --silent && node ./scripts/after-build.cjs
babelHelpers: 'bundled' option was used by default. It is recommended to configure this option explicitly, read more here: https://github.com/rollup/plugins/tree/master/packages/babel#babelhelpers
[!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
src\path.ts (13:23)
11:  * @returns
12:  */
13: async function appDir(): Promise<string> {
                           ^
14:   return invokeTauriCommand<string>({
15:     __tauriModule: 'Fs',
Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
    at error (C:\Users\ASUS\Dev\tauri\tooling\api\node_modules\rollup\dist\shared\rollup.js:5305:30)
    at Module.error (C:\Users\ASUS\Dev\tauri\tooling\api\node_modules\rollup\dist\shared\rollup.js:9750:16)
    at Module.tryParse (C:\Users\ASUS\Dev\tauri\tooling\api\node_modules\rollup\dist\shared\rollup.js:10156:25)
    at Module.setSource (C:\Users\ASUS\Dev\tauri\tooling\api\node_modules\rollup\dist\shared\rollup.js:10057:24)
    at ModuleLoader.addModuleSource (C:\Users\ASUS\Dev\tauri\tooling\api\node_modules\rollup\dist\shared\rollup.js:18403:20)
    at ModuleLoader.fetchModule (C:\Users\ASUS\Dev\tauri\tooling\api\node_modules\rollup\dist\shared\rollup.js:18459:9)
    at async Promise.all (index 2)

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

The steps I followed are such:

  1. Clone the repo, dev branch
  2. run ./scripts/setup.ps1

I've been able to narrow the issue down to the yarn build command that runs in tooling/api.

Interestingly, the specific file that produces the error varies each time, I have no idea why.

But each time the issue seems to be the same, namely for some reason rollup tries to interpret a TypeScript file as if it were JavaScript, and it predictably fails.

I have been able to "fix" this issue by removing the resolve plugin in rollup.config.js like so:

    // code omited for brevity
    plugins: [
      commonjs({}),
      // remove the resolve plugin.
      // resolve({
      //   // pass custom options to the resolve plugin
      //   customResolveOptions: {
      //     moduleDirectories: ['node_modules']
      //   }
      // }),
      typescript({
        tsconfig: './tsconfig.json'
      }),
      babel({
        configFile: false,
        presets: [['@babel/preset-env'], ['@babel/preset-typescript']]
      }),
      terser()
    ],
    // code omited for brevity

I have no idea why this works, and I would suspect this could cause all kinds of issues so I'm not submitting a PR.

OS: Windows 10
Node: v14.16.1 (LTS)
Yarn: 1.22.10

@lucasfernog
Copy link
Member

I just tried on the same OS, Node.js and Yarn versions and I couldn't reproduce it :( I'll have to close this, a lot of people successfully built the API package, I just think something weird happened on your install.

@BenoitRanque
Copy link
Contributor Author

thank you for taking the time to review this

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

No branches or pull requests

2 participants