Anber / wyw-in-js

MIT License
191 stars 8 forks source link

The 'declare' modifier is only allowed when the 'allowDeclareFields' option of @babel/plugin-transform-typescript or @babel/preset-typescript is enabled #84

Open ntucker opened 1 month ago

ntucker commented 1 month ago

Environment

Description

ERROR in ./src/pages/IssueDetail/CreateComment.tsx
Module build failed (from ./node_modules/@wyw-in-js/webpack-loader/lib/index.js):
SyntaxError: /home/projects/aoniolzby.github/src/resources/Issue.tsx: The 'declare' modifier is only allowed when the 'allowDeclareFields' option of @babel/plugin-transform-typescript or @babel/preset-typescript is enabled.
  23 |   declare readonly draft?: boolean;
  24 |   get stateIcon() {
> 25 |     return stateToIcon[this.state];
     |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  26 |   }
  27 |   get owner() {
  28 |     const pieces = this.repositoryUrl.split('/');
    at File.buildCodeFrameError (file:///home/projects/aoniolzby.github/node_modules/@babel/core/lib/transformation/file/file.js:202:12)
    at NodePath.buildCodeFrameError (file:///home/projects/aoniolzby.github/node_modules/@babel/traverse/lib/path/index.js:98:21)
    at Object.field (file:///home/projects/aoniolzby.github/node_modules/@babel/plugin-transform-typescript/lib/index.js:73:22)
    at eval (file:///home/projects/aoniolzby.github/node_modules/@babel/plugin-transform-typescript/lib/index.js:360:33)
    at Array.forEach (<anonymous>)
    at PluginPass.Class (file:///home/projects/aoniolzby.github/node_modules/@babel/plugin-transform-typescript/lib/index.js:352:31)
    at newFn (file:///home/projects/aoniolzby.github/node_modules/@babel/traverse/lib/visitors.js:160:14)
    at NodePath._call (file:///home/projects/aoniolzby.github/node_modules/@babel/traverse/lib/path/context.js:46:20)
    at NodePath.call (file:///home/projects/aoniolzby.github/node_modules/@babel/traverse/lib/path/context.js:36:17)
    at NodePath.visit (file:///home/projects/aoniolzby.github/node_modules/@babel/traverse/lib/path/context.js:82:31)

This worked fine in previous versions. Only started happening over the latest update.

Reproducible Demo

Code: https://github.com/reactive/data-client/tree/master/examples/github-app File that triggers: https://github.com/reactive/data-client/blob/master/examples/github-app/src/resources/Issue.tsx Stackblitz location to see error : https://stackblitz.com/github/reactive/data-client/tree/master/examples/github-app?file=src%2Fresources%2FIssue.tsx Webpack config wyw-in-js integration: https://github.com/ntucker/anansi/blob/60736b7b2b13fd3d30a24c8a7f4365d525c6157b/packages/webpack-config-anansi/src/base/index.js#L79 Related babel config integration: https://github.com/ntucker/anansi/blob/60736b7b2b13fd3d30a24c8a7f4365d525c6157b/packages/babel-preset-anansi/index.js#L27