0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

@nuxt/typescript-runtimeでデコレーターを使う際の注意点

Posted at

最新のnuxt.jsを使ってtypescript-runtime上でデコレーターを使うと以下のようなエラーが出ることがある。
(universalモードの場合)

ParseError: Support for the experimental syntax 'decorators-legacy' isn't currently enabled (3:1)

...
at p (node_modules/jiti/dist/jiti.js:1:9442)
...

これは、内部でjitiというトランスパイラが勝手に呼ばれていることが原因である。

解決法

typescript-runtimeの場合はts-nodeによって自動的にトランスパイルされるので、jitiは無用の長物である。
したがって、jitiを使わないように設定する必要がある。

具体的には、nuxt.config.tsにcreateRequire: 'native'を追加すればよい。
(ドキュメントには書いてないが実際動作するようである。(nuxt@2.15.0にて確認))

nuxt.config.ts
module.exports = {
  createRequire: 'native',
  // ...
}:
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?