nuxt: Rollup parse problem after upgrade to Nuxt 3.2.0
Environment
- Operating System:
Linux - Node Version:
v19.6.0 - Nuxt Version:
3.2.0 - Nitro Version:
2.2.1 - Package Manager:
pnpm@7.27.0 - Builder:
vite - User Config:
modules,oxyshopNuxt,i18n,experimental,build - Runtime Modules:
normalizedModule(),normalizedModule() - Build Modules:
-
Reproduction
Describe the bug
After upgrading to Nuxt 3.2.0 on projects using my Nuxt module, I started getting the following error. I don’t really know what to do, I tried disabling experimental client-only treeshake and try transpiling the module, without success.
WARN rollup-plugin-inject: failed to parse /app/node_modules/.pnpm/@oxyshop+nuxt@1.16.16/node_modules/@oxyshop/nuxt/src/runtime/middleware/ipKiller.ts. Consider restricting the plugin to particular files via options.include
ERROR RollupError: Unexpected token (Note that you need plugins to import files that are not JavaScript)
2: import { defineEventHandler, createError } from 'h3'
3:
4: function isAwsHostValid(host: string | undefined) {
^
5: if (!host) {
6: return false
✔ Nitro built in 7955 ms
Additional context
if you install the test-module as a dependency in another project, you will get this error.
Logs
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 9
- Comments: 23 (13 by maintainers)
@japboy you’ve only given the
graphqlplugin tovite’s Rollup config, but you’re also using graphql files in your Nitro server handlers.To fix your issue, you need to also pass graphql plugin to nitro’s rollup config:
I also ran into this, when
importing a ts file directly that is part of an (internal) node package:Before upgrading, it worked.
@sPaCeMoNk3yIam Thats true.
@danielroe If you import any raw
.tsfile from an package located innode_modules, you will get the following rollup error inNuxt 3.2.0. Do you have any ideas?I was also experiencing this same problem with Nuxt
3.6.5I fixed it by adding this to nuxt.config.ts:
I face the problem @rollup of vite when run build
ERROR "extname" is not exported by "__vite-browser-external", imported by "node_modules/@rollup/pluginutils/dist/es/index.js".I’m encountering the same issue; the config build.transpile option isn’t functioning. You can configure server/tsconfig.json to exclude node_modules. Keep in mind that the project has two tsconfig.json files, not just the one at the root directory.
ℹ ✓ built in 13.04s 17:34:27 ✔ Server built in 13060ms 17:34:27 ✔ Generated public .output/public nitro 17:34:27 ℹ Building Nitro Server (preset: node-server) nitro 17:34:27 (inject plugin) rollup-plugin-inject: failed to parse F:/project-lmq/learn-self-study/bingo-book/j2-book/node_modules/ali-oss/lib/common/client/getReqUrl.ts. Consider restricting the plugin to particular files via options.include (inject plugin) rollup-plugin-inject: failed to parse F:/project-lmq/learn-self-study/bingo-book/j2-book/node_modules/ali-oss/lib/common/utils/createRequest.ts. Consider restricting the plugin to particular files via options.include (inject plugin) rollup-plugin-inject: failed to parse F:/project-lmq/learn-self-study/bingo-book/j2-book/node_modules/ali-oss/lib/common/utils/encoder.ts. Consider restricting the plugin to particular files via options.include (inject plugin) rollup-plugin-inject: failed to parse F:/project-lmq/learn-self-study/bingo-book/j2-book/node_modules/ali-oss/lib/common/utils/setSTSToken.ts. Consider restricting the plugin to particular files via options.include (inject plugin) rollup-plugin-inject: failed to parse F:/project-lmq/learn-self-study/bingo-book/j2-book/node_modules/ali-oss/lib/common/utils/isFunction.ts. Consider restricting the plugin to particular files via options.include (inject plugin) rollup-plugin-inject: failed to parse F:/project-lmq/learn-self-study/bingo-book/j2-book/node_modules/ali-oss/lib/common/utils/retry.ts. Consider restricting the plugin to particular files via options.include (esbuild plugin) [esbuild] (.nuxt/dist/server/_nuxt/writer-5235dab7.js:1563:10) This assignment will throw because “cur_notebook” is a constant (inject plugin) rollup-plugin-inject: failed to parse F:/project-lmq/learn-self-study/bingo-book/j2-book/node_modules/ali-oss/lib/common/utils/isBuffer.ts. Consider restricting the plugin to particular files via options.include (inject plugin) rollup-plugin-inject: failed to parse F:/project-lmq/learn-self-study/bingo-book/j2-book/node_modules/ali-oss/lib/common/utils/obj2xml.ts. Consider restricting the plugin to particular files via options.include (inject plugin) rollup-plugin-inject: failed to parse F:/project-lmq/learn-self-study/bingo-book/j2-book/node_modules/ali-oss/lib/common/utils/checkBucketName.ts. Consider restricting the plugin to particular files via options.include (inject plugin) rollup-plugin-inject: failed to parse F:/project-lmq/learn-self-study/bingo-book/j2-book/node_modules/ali-oss/lib/common/utils/deepCopy.ts. Consider restricting the plugin to particular files via options.include (inject plugin) rollup-plugin-inject: failed to parse F:/project-lmq/learn-self-study/bingo-book/j2-book/node_modules/ali-oss/lib/common/utils/setRegion.ts. Consider restricting the plugin to particular files via options.include (inject plugin) rollup-plugin-inject: failed to parse F:/project-lmq/learn-self-study/bingo-book/j2-book/node_modules/ali-oss/lib/common/utils/checkConfigValid.ts. Consider restricting the plugin to particular files via options.include (inject plugin) rollup-plugin-inject: failed to parse F:/project-lmq/learn-self-study/bingo-book/j2-book/node_modules/ali-oss/lib/common/bucket/getBucketInventory.ts. Consider restricting the plugin to particular files via options.include (inject plugin) rollup-plugin-inject: failed to parse F:/project-lmq/learn-self-study/bingo-book/j2-book/node_modules/ali-oss/lib/common/bucket/completeBucketWorm.ts. Consider restricting the plugin to particular files via options.include (inject plugin) rollup-plugin-inject: failed to parse F:/project-lmq/learn-self-study/bingo-book/j2-book/node_modules/ali-oss/lib/common/bucket/deleteBucketInventory.ts. Consider restricting the plugin to particular files via options.include (inject plugin) rollup-plugin-inject: failed to parse F:/project-lmq/learn-self-study/bingo-book/j2-book/node_modules/ali-oss/lib/common/bucket/putBucketInventory.ts. Consider restricting the plugin to particular files via options.include (inject plugin) rollup-plugin-inject: failed to parse F:/project-lmq/learn-self-study/bingo-book/j2-book/node_modules/ali-oss/lib/common/bucket/abortBucketWorm.ts. Consider restricting the plugin to particular files via options.include (inject plugin) rollup-plugin-inject: failed to parse F:/project-lmq/learn-self-study/bingo-book/j2-book/node_modules/ali-oss/lib/common/bucket/initiateBucketWorm.ts. Consider restricting the plugin to particular files via options.include (inject plugin) rollup-plugin-inject: failed to parse F:/project-lmq/learn-self-study/bingo-book/j2-book/node_modules/ali-oss/lib/common/bucket/extendBucketWorm.ts. Consider restricting the plugin to particular files via options.include (inject plugin) rollup-plugin-inject: failed to parse F:/project-lmq/learn-self-study/bingo-book/j2-book/node_modules/ali-oss/lib/common/bucket/listBucketInventory.ts. Consider restricting the plugin to particular files via options.include (inject plugin) rollup-plugin-inject: failed to parse F:/project-lmq/learn-self-study/bingo-book/j2-book/node_modules/ali-oss/lib/common/bucket/getBucketWorm.ts. Consider restricting the plugin to particular files via options.include (inject plugin) rollup-plugin-inject: failed to parse F:/project-lmq/learn-self-study/bingo-book/j2-book/node_modules/ali-oss/lib/common/object/postAsyncFetch.ts. Consider restricting the plugin to particular files via options.include (inject plugin) rollup-plugin-inject: failed to parse F:/project-lmq/learn-self-study/bingo-book/j2-book/node_modules/ali-oss/lib/common/object/getAsyncFetch.ts. Consider restricting the plugin to particular files via options.include (inject plugin) rollup-plugin-inject: failed to parse F:/project-lmq/learn-self-study/bingo-book/j2-book/node_modules/ali-oss/lib/common/utils/checkBucketTag.ts. Consider restricting the plugin to particular files via options.include (inject plugin) rollup-plugin-inject: failed to parse F:/project-lmq/learn-self-study/bingo-book/j2-book/node_modules/ali-oss/lib/common/utils/formatObjKey.ts. Consider restricting the plugin to particular files via options.include (inject plugin) rollup-plugin-inject: failed to parse F:/project-lmq/learn-self-study/bingo-book/j2-book/node_modules/ali-oss/lib/common/utils/policy2Str.ts. Consider restricting the plugin to particular files via options.include
ERROR RollupError: Unexpected keyword ‘this’ (Note that you need plugins to import files that are not JavaScript) nitro 17:35:31
7: import { checkConfigValid } from ‘…/utils/checkConfigValid’; 8: 9: export function getReqUrl(this: any, params) { ^ 10: const ep: any = {}; 11: const isCname = this.options.cname;
ERROR Unexpected keyword ‘this’ (Note that you need plugins to import files that are not JavaScript)
me too ,how to do this question ,
I think it would be very helpful if there was a better error message saying that the module needs to be added to the
build.transpile, otherwise it’s a lot of wasted time trying to figure out why it is not working.Closing as this is basically about ensuring that modules that use TypeScript or otherwise need to be transpiled, are added to
build.transpile, rather than an issue with Nuxt.Yes, I tried, it didn’t help.
Hey! Could you kindly provide a reproduction? 🙏