Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use ts-node to run custom script in Expo project #929

Closed
Lpaydat opened this issue Dec 25, 2019 · 5 comments
Closed

Cannot use ts-node to run custom script in Expo project #929

Lpaydat opened this issue Dec 25, 2019 · 5 comments

Comments

@Lpaydat
Copy link

Lpaydat commented Dec 25, 2019

Hello, noob here.

I have some ReactJs project which is run perfectly on every aspect.
But recently I want to make it monorepo and I chose Expo for this job.

I can make most of code works except some custom scripts.
It say SyntaxError: Cannot use import statement outside a module and the line of code that lead to this error was node_modules/expo/AppEntry.js which is in the main parameter in package.json.

This is the full log:

$ ts-node -r tsconfig-paths/register --project scripts/helpers/tsconfig.json scripts/customScript.ts
/home/username/Workspace/project/node_modules/expo/AppEntry.js:1
import 'expo/build/Expo.fx';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:1050:16)
    at Module._compile (internal/modules/cjs/loader.js:1098:27)
    at Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
    at Object.require.extensions.<computed> [as .js] (/home/username/Workspace/project/node_modules/ts-node/src/index.ts:529:44)
    at Module.load (internal/modules/cjs/loader.js:983:32)
    at Function.Module._load (internal/modules/cjs/loader.js:891:14)
    at Module.require (internal/modules/cjs/loader.js:1023:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/home/username/Workspace/project/scripts/helpers/customScript.ts:2:1)
    at Module._compile (internal/modules/cjs/loader.js:1128:30)
error Command failed with exit code 1.

and this is the content of scripts/helpers/tsconfig.json:

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "jsx": "preserve",
    "lib": ["dom", "esnext"],
    "moduleResolution": "node",
    "noEmit": true,
    "skipLibCheck": true,
    "resolveJsonModule": true,
    "target": "es5",
    "allowJs": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "esModuleInterop": true,
    "module": "commonjs",
    "isolatedModules": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "noImplicitThis": false
  },
  "exclude": ["node_modules"],
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
}

This error not occur on every scripts, just some custom script commands and all error disappear if I remove main field from package.json.

I tried to search for solution for hours and tried a bunch of methods with no results. T__T

@blakeembrey
Copy link
Member

Do you have a reproduction I can try?

@Lpaydat
Copy link
Author

Lpaydat commented Dec 27, 2019

@blakeembrey Sorry for late reply.

I have created an example to reproduce this error, you can see it here ts-node-next-expo.

It's the customScript command.

@trusktr
Copy link

trusktr commented Jan 2, 2020

@Lpaydat Are you on Node.js 13?

@trusktr
Copy link

trusktr commented Jan 2, 2020

Just checked it out, node_modules/expo/AppEntry.js is an ES Module. The issue is #935

@cspotcode
Copy link
Collaborator

Assuming the most recent comment is accurate, we can close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants