Next.js script - SyntaxError: Unexpected token '<' #1965
Unanswered
tomasvorel2
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey everyone,
I'm running into issues when I try to run a script in my
Next.js
(version12.3.2
) project usingts-node
. I'm using all kinds of util functions from all across the project. When I want to run the script, I get an error pointing to one of my React components (which I'm not using/importing inside the script file), more specifically to an import of a static file:import staticFile from 'public/img/static-file.svg'
. This actually applies to everything that is notjsx
(.css files etc.) which makes sense as I have thejsx
option set toreact
in mycompilerOptions
. However, I'd like to simply "make the script run" without Typescript yelling at me. I googled for solutions, tried adding.d.ts
files with module declarations (not sure if that was even something that could help) but without success. I'm about 87% sure the issue is in an incorrect setup of mytsconfig.json
but I'm far from an expert when it comes to compiler setup, so I cannot tell where. I'd be grateful for any pointers.Script command
"the-script": "ts-node -r tsconfig-paths/register ./src/scripts/the-script.ts",
Package versions
ts-node version -
10.9.1
typescript version -
4.9.4
node version -
19.3.0
My
tsconfig.json
{
"ts-node": {
"transpileOnly": true,
"files": true,
"compilerOptions": {
"module": "CommonJS",
"allowJs": true
}
},
"compilerOptions": {
"target": "es2015",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noUnusedLocals": true,
"noEmit": true,
"esModuleInterop": true,
"module": "ESNext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react",
"baseUrl": ".",
"paths": {
"@/lib/": ["lib/"],
"@/components/": ["src/components/"],
"@/data/": ["src/data/"],
"@/styles/": ["src/styles/"],
"@/utils/": ["src/utils/"],
"@/services/": ["src/services/"],
"@/models/": ["src/models/"],
"@/interfaces/": ["src/interfaces/"],
"@/constants/": ["src/constants/"],
"@/middleware/": ["src/middleware/"],
"@/hooks/": ["src/hooks/"],
"@/guards/": ["src/guards/"],
"@/public/": ["public/"],
"@/static/": ["static/"]
},
"incremental": true
},
"include": ["next-env.d.ts", "additional.d.ts", "/*.ts", "/*.tsx"],
"exclude": ["node_modules"]
}
Error:
Beta Was this translation helpful? Give feedback.
All reactions