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

Absolute Imports Not Working in Javascript Project #465

Closed
JoseRFelix opened this issue May 4, 2020 · 1 comment · Fixed by blitz-js/blitz#433
Closed

Absolute Imports Not Working in Javascript Project #465

JoseRFelix opened this issue May 4, 2020 · 1 comment · Fixed by blitz-js/blitz#433

Comments

@JoseRFelix
Copy link
Contributor

What is the problem?

As per title.

Steps to Reproduce:

  1. Create a Javascript project with blitz new app --js
  2. Create any component
  3. Import it in a page

Versions:

debug: local
debug: pkgPath: /home/jfelix/Documents/programming/open-source/test-m2/node_modules/@blitzjs/cli 

Linux 5.3 | linux-x64 | Node: v12.16.1

blitz: 0.8.2 (global)
blitz: 0.8.2 (local)

Supporting Documentation

Error Log:

./pages/_app.js
Module not found: Can't resolve 'app/styles/theme' in '/home/jfelix/Documents/programming/open-source/test-m2/.blitz/caches/dev/pages'
Error: Cannot find module '/home/jfelix/Documents/programming/open-source/test-m2/.blitz/caches/dev/.next/server/static/development/pages/_document'
Require stack:
- /home/jfelix/Documents/programming/open-source/test-m2/node_modules/next/dist/next-server/server/load-components.js
- /home/jfelix/Documents/programming/open-source/test-m2/node_modules/next/dist/next-server/server/api-utils.js
- /home/jfelix/Documents/programming/open-source/test-m2/node_modules/next/dist/next-server/server/next-server.js
- /home/jfelix/Documents/programming/open-source/test-m2/node_modules/next/dist/server/next.js
- /home/jfelix/Documents/programming/open-source/test-m2/node_modules/next/dist/server/lib/start-server.js
- /home/jfelix/Documents/programming/open-source/test-m2/node_modules/next/dist/cli/next-dev.js
- /home/jfelix/Documents/programming/open-source/test-m2/node_modules/next/dist/bin/next
- /home/jfelix/Documents/programming/open-source/test-m2/node_modules/@blitzjs/server/bin/next-patched
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)
    at Function.Module._load (internal/modules/cjs/loader.js:864:27)
    at Module.require (internal/modules/cjs/loader.js:1044:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.loadComponents (/home/jfelix/Documents/programming/open-source/test-m2/node_modules/next/dist/next-server/server/load-components.js:24:25)
    at DevServer.findPageComponents (/home/jfelix/Documents/programming/open-source/test-m2/node_modules/next/dist/next-server/server/next-server.js:555:60)
    at DevServer.renderErrorToHTML (/home/jfelix/Documents/programming/open-source/test-m2/node_modules/next/dist/next-server/server/next-server.js:852:33)
    at DevServer.renderErrorToHTML (/home/jfelix/Documents/programming/open-source/test-m2/node_modules/next/dist/server/next-dev-server.js:19:915)
    at async DevServer.render (/home/jfelix/Documents/programming/open-source/test-m2/node_modules/next/dist/next-server/server/next-server.js:540:22)
    at async Object.fn (/home/jfelix/Documents/programming/open-source/test-m2/node_modules/next/dist/next-server/server/next-server.js:390:17)
    at async Router.execute (/home/jfelix/Documents/programming/open-source/test-m2/node_modules/next/dist/next-server/server/router.js:134:32)
    at async DevServer.run (/home/jfelix/Documents/programming/open-source/test-m2/node_modules/next/dist/next-server/server/next-server.js:505:29)
    at async DevServer.handleRequest (/home/jfelix/Documents/programming/open-source/test-m2/node_modules/next/dist/next-server/server/next-server.js:149:20) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/jfelix/Documents/programming/open-source/test-m2/node_modules/next/dist/next-server/server/load-components.js',
    '/home/jfelix/Documents/programming/open-source/test-m2/node_modules/next/dist/next-server/server/api-utils.js',
    '/home/jfelix/Documents/programming/open-source/test-m2/node_modules/next/dist/next-server/server/next-server.js',
    '/home/jfelix/Documents/programming/open-source/test-m2/node_modules/next/dist/server/next.js',
    '/home/jfelix/Documents/programming/open-source/test-m2/node_modules/next/dist/server/lib/start-server.js',
    '/home/jfelix/Documents/programming/open-source/test-m2/node_modules/next/dist/cli/next-dev.js',
    '/home/jfelix/Documents/programming/open-source/test-m2/node_modules/next/dist/bin/next',
    '/home/jfelix/Documents/programming/open-source/test-m2/node_modules/@blitzjs/server/bin/next-patched'
  ]
}

Compiled code:

image

@wKovacs64
Copy link
Contributor

Confirmed. Thanks for the report! Blitz needs to generate a jsconfig.json when a JS project is created in order for absolute paths to work. In the meantime, you can create your own in the project root with the following contents (or use relative paths, temporarily):

{
  "compilerOptions": {
    "baseUrl": "."
  }
}

You may run into another issue at that point, but it should get you past this one! 😄

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

Successfully merging a pull request may close this issue.

3 participants