grafana / k6-template-typescript

Template to use TypeScript with k6

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Babel error when running webpack with no modifications

deadwards90 opened this issue · comments

I've tried pulling down the repo and tried running the following commands as set out in the readme.

yarn install
yarn webpack

Upon running, I get the following errors:

Hash: 425773d28b54dd08feef
Version: webpack 4.43.0
Time: 243ms
Built at: 09/02/2021 15:59:12
   Asset      Size  Chunks             Chunk Names
test1.js  8.54 KiB   test1  [emitted]  test1
test2.js  8.44 KiB   test2  [emitted]  test2
Entrypoint test1 = test1.js
Entrypoint test2 = test2.js
[./test1.ts] 4.22 KiB {test1} [built] [failed] [1 error]
[./test2.ts] 4.13 KiB {test2} [built] [failed] [1 error]

ERROR in ./test1.ts
Module build failed (from ../node_modules/babel-loader/lib/index.js):
SyntaxError: D:\dev\wealthkernel\template-typescript\src\test1.ts: Unexpected token, expected ";" (5:18)

  3 | import http from 'k6/http';
  4 |
> 5 | export let options:Options = {
    |                   ^
  6 |   vus: 50,
  7 |   duration: '10s'
  8 | };
    at Parser._raise (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:746:17)
    at Parser.raiseWithData (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:739:17)
    at Parser.raise (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:733:17)
    at Parser.unexpected (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:8807:16)
    at Parser.semicolon (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:8789:40)
    at Parser.parseVarStatement (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:11625:10)
    at Parser.parseStatementContent (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:11223:21)
    at Parser.parseStatement (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:11156:17)
    at Parser.parseExportDeclaration (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:12365:17)
    at Parser.maybeParseExportDeclaration (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:12321:31)
    at Parser.parseExport (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:12251:29)
    at Parser.parseStatementContent (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:11260:27)
    at Parser.parseStatement (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:11156:17)
    at Parser.parseBlockOrModuleBlockBody (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:11731:25)
    at Parser.parseBlockBody (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:11717:10)
    at Parser.parseTopLevel (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:11087:10)
    at Parser.parse (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:12768:10)
    at parse (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:12821:38)
    at parser (D:\dev\wealthkernel\template-typescript\node_modules\@babel\core\lib\parser\index.js:54:34)
    at parser.next (<anonymous>)
    at normalizeFile (D:\dev\wealthkernel\template-typescript\node_modules\@babel\core\lib\transformation\normalize-file.js:93:38)
    at normalizeFile.next (<anonymous>)
    at run (D:\dev\wealthkernel\template-typescript\node_modules\@babel\core\lib\transformation\index.js:31:50)
    at run.next (<anonymous>)
    at Function.transform (D:\dev\wealthkernel\template-typescript\node_modules\@babel\core\lib\transform.js:27:41)
    at transform.next (<anonymous>)
    at step (D:\dev\wealthkernel\template-typescript\node_modules\gensync\index.js:254:32)
    at D:\dev\wealthkernel\template-typescript\node_modules\gensync\index.js:266:13
    at async.call.result.err.err (D:\dev\wealthkernel\template-typescript\node_modules\gensync\index.js:216:11)
    at D:\dev\wealthkernel\template-typescript\node_modules\gensync\index.js:184:28

ERROR in ./test2.ts
Module build failed (from ../node_modules/babel-loader/lib/index.js):
SyntaxError: D:\dev\wealthkernel\template-typescript\src\test2.ts: Unexpected token, expected ";" (5:18)

  3 | import http from 'k6/http';
  4 |
> 5 | export let options:Options = {
    |                   ^
  6 |   vus: 50,
  7 |   duration: '10s'
  8 | };
    at Parser._raise (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:746:17)
    at Parser.raiseWithData (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:739:17)
    at Parser.raise (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:733:17)
    at Parser.unexpected (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:8807:16)
    at Parser.semicolon (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:8789:40)
    at Parser.parseVarStatement (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:11625:10)
    at Parser.parseStatementContent (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:11223:21)
    at Parser.parseStatement (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:11156:17)
    at Parser.parseExportDeclaration (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:12365:17)
    at Parser.maybeParseExportDeclaration (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:12321:31)
    at Parser.parseExport (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:12251:29)
    at Parser.parseStatementContent (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:11260:27)
    at Parser.parseStatement (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:11156:17)
    at Parser.parseBlockOrModuleBlockBody (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:11731:25)
    at Parser.parseBlockBody (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:11717:10)
    at Parser.parseTopLevel (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:11087:10)
    at Parser.parse (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:12768:10)
    at parse (D:\dev\wealthkernel\template-typescript\node_modules\@babel\parser\lib\index.js:12821:38)
    at parser (D:\dev\wealthkernel\template-typescript\node_modules\@babel\core\lib\parser\index.js:54:34)
    at parser.next (<anonymous>)
    at normalizeFile (D:\dev\wealthkernel\template-typescript\node_modules\@babel\core\lib\transformation\normalize-file.js:93:38)
    at normalizeFile.next (<anonymous>)
    at run (D:\dev\wealthkernel\template-typescript\node_modules\@babel\core\lib\transformation\index.js:31:50)
    at run.next (<anonymous>)
    at Function.transform (D:\dev\wealthkernel\template-typescript\node_modules\@babel\core\lib\transform.js:27:41)
    at transform.next (<anonymous>)
    at step (D:\dev\wealthkernel\template-typescript\node_modules\gensync\index.js:254:32)
    at D:\dev\wealthkernel\template-typescript\node_modules\gensync\index.js:266:13
    at async.call.result.err.err (D:\dev\wealthkernel\template-typescript\node_modules\gensync\index.js:216:11)
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I assume I'm doing something stupid here but not sure what. Any advice?

I think I've solved it (although not sure why it's not working as is).

It was not picking up anything in the .babelrc file, so I moved that into the rules part of the webpack config.

Hi,

I'm unable to reproduce this error on Windows or macOS.

Windows+ node v15.3.0

Hash: 6e1b2d0cc3c0675c3eba
Version: webpack 4.43.0
Time: 1300ms
Built at: 03/10/2021 11:59:10 AM
   Asset      Size  Chunks             Chunk Names
test1.js  5.48 KiB   test1  [emitted]  test1
test2.js  5.49 KiB   test2  [emitted]  test2
Entrypoint test1 = test1.js
Entrypoint test2 = test2.js
[./test1.ts] 317 bytes {test1} [built]
[./test2.ts] 326 bytes {test2} [built]
[k6] external "k6" 42 bytes {test1} {test2} [built]
[k6/http] external "k6/http" 42 bytes {test1} {test2} [built]
Done in 2.59s.

macOS + zsh + node v14.14.0

Version: webpack 4.43.0
Time: 834ms
Built at: 03/10/2021 11:57:15 AM
   Asset      Size  Chunks             Chunk Names
test1.js  5.48 KiB   test1  [emitted]  test1
test2.js  5.49 KiB   test2  [emitted]  test2
Entrypoint test1 = test1.js
Entrypoint test2 = test2.js
[./test1.ts] 317 bytes {test1} [built]
[./test2.ts] 326 bytes {test2} [built]
[k6] external "k6" 42 bytes {test1} {test2} [built]
[k6/http] external "k6/http" 42 bytes {test1} {test2} [built]
✨  Done in 1.70s.

One thing I noticed is that you keep your source code on a separate drive(letter). This has been known to cause issues previously with some node modules. Although when trying this to reproduce the error, I still can't get it to break. What NodeJS version are you on?

My apologies @simskij for not getting back to you, I must have acknowledged the notification without realising you had responded.

I was using v14.15.4.

The same problem - macOS + node v17.8.0

./src/get-200-status-test.ts 39 bytes [built] [code generated] [1 error]
./src/post-400-status-test.ts 39 bytes [built] [code generated] [1 error]
./src/post-file-test.ts 39 bytes [built] [code generated] [1 error]

3 | import http from 'k6/http';
4 |

5 | export let options:Options = {
| ^
6 | vus: 50,
7 | duration: '10s'
8 | };

Hi @GhMartingit I just ran it v17.8.0 in docker and it ran fine[1].

It seems like you have differnt files than the ones in the default template, which is expected to be honest ;). But can you please run the template as it is and see if that work?

edit: I am an idiot and did not run with the latest version 🤦 And when I do it still works as before, but it seems like you are actually using the latest version. Is that true and have you done any modifications?

[1] With the exception that I hit this and hat to use this answer to get it to work.

The same (but without the workaround) is true for v14.15.4 @dantheman999301. Can you as well try with the current latest version?

Hi @GhMartingit I just ran it v17.8.0 in docker and it ran fine[1].

It seems like you have differnt files than the ones in the default template, which is expected to be honest ;). But can you please run the template as it is and see if that work?

edit: I am an idiot and did not run with the latest version 🤦 And when I do it still works as before, but it seems like you are actually using the latest version. Is that true and have you done any modifications?

[1] With the exception that I hit this and hat to use this answer to get it to work.

I did some modification. Default template is working.

Thanks @mstoykov

@mstoykov Didn't work running it in the same way I was before.

However something in the original comment by @simskij made me realise that I have a slightly odd way of working.

I have two Windows drives (C: and D:) and I keep all of my development files on D:. However because of the way a lot of terminals work, I have a symlinked folder in my Users folder that points to a folder on D:.

This looks to be what is causing the issue. If I don't go through the symlink and run webpack on the same folder, it works fine. So nothing wrong with the template, just node or webpack being a bit strange I guess. Been a long time since I've looked at webpack so I have no idea if this is even easily solvable.

Not a big deal in any case!

Thanks both of you, for figuring this out 🙇